目前正在开发一个Eclipse插件,我想制作一个在创建/显示时不关注的Shell。
我试过使用SWT.NO_FOCUS但无济于事。
如何在不将焦点从您所在的另一个应用程序/窗口移开的情况下创建 Shell?
下面的代码将打开一个新Shell
,而不会将焦点从父级移开:
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout());
Button button = new Button(shell, SWT.PUSH);
button.setText("Open new Shell");
button.addListener(SWT.Selection, (event) -> {
Shell child = new Shell(shell);
child.setText("Child");
child.setVisible(true);
child.setSize(300,200);
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
对于工具提示外壳之类的东西,请使用:
new Shell(parent, SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS);