当用户使用窗口关闭按钮(红色 X)按钮关闭任何应用程序窗口时。它导致 Widget is Disposed 问题与我的应用程序有关。当他们使用我提供的关闭应用程序关闭窗口时。一切正常。
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Close Aplot", true);
}
@Override
protected void okPressed() {
getShell().setVisible(false);
}
- 你能捕获窗口关闭按钮(红色 X)的按下来使用上面的代码吗?
- 您可以禁用窗口关闭按钮(红色 X)吗?
最佳答案
在 Shell
上监听 SWT.Close
。
This应该有帮助:
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.addListener(SWT.Close, new Listener()
{
public void handleEvent(Event event)
{
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setText("Information");
messageBox.setMessage("Close the shell?");
event.doit = messageBox.open() == SWT.YES;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
它将提示用户验证决定。
关于java - SWT - 修改窗口关闭按钮(红色 X),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16899807/