当用户使用窗口关闭按钮(红色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);
}
Run Code Online (Sandbox Code Playgroud)
倾听SWT.Close的Shell.
这应该有所帮助:
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();
}
Run Code Online (Sandbox Code Playgroud)
它将提示用户验证决定.
| 归档时间: |
|
| 查看次数: |
7148 次 |
| 最近记录: |