java – 单击外部关闭SWT shell
作者:互联网
我有这个JFace对话框:
setShellStyle(SWT.APPLICATION_MODAL | SWT.CLOSE);
setBlockOnOpen(false);
是否可以通过单击对话框外的某个位置来关闭它?
也许就像在整个屏幕上监听点击事件并检测它是否在对话框之外,然后关闭.
解决方法:
您可以将SWT.Deactivate侦听器附加到对话框的基础Shell.
要附加侦听器,您可以覆盖Window :: configureShell,如下所示:
@Override
protected void configureShell( Shell shell ) {
super.configureShell( shell );
shell.addListener( SWT.Deactivate, event -> shell.close() );
}
这里有一个独立的SWT示例来说明裸机制:
Display display = new Display();
Shell parentShell = new Shell(display);
parentShell.setSize(500, 500);
parentShell.open();
Shell shell = new Shell(parentShell);
shell.addListener(SWT.Deactivate, event -> shell.close());
shell.setSize(300, 300);
shell.setText("Closes on Deactivate");
shell.open();
while (!parentShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
标签:java,dialog,swt,jface 来源: https://codeday.me/bug/20190705/1389356.html