2016-02-23 19 views
0

當前正在開發一個Eclipse插件,我想創建一個在創建/顯示時不需要關注的Shell。新的SWT Shell沒有關注?

我試過使用SWT.NO_FOCUS,但無濟於事。

如何在不關注另一個應用程序/窗口的情況下創建Shell?

回答

2

下面的代碼將打開一個新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(); 
+0

我打開shell的方式給了我麻煩,我使用的是Shell.open(),而不是setVisible(true)。謝謝你的樣品。 –

+0

@ VladIlie很高興爲你工作。首先調用'open()',因爲這就是你通常所做的。 – Baz

1

對於類似的工具提示使用貝:

new Shell(parent, SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS); 
+0

我試過這個構造函數,但重點是仍然從GUI中的其他組件中拿走。我也從這裏嘗試了Baz的setEnable(false)建議http://stackoverflow.com/questions/26120040/how-can-i-open-a-shell-without-making-it-active但是,似乎只有竊取其他應用程序的重點。 –

+0

向我們展示一些代碼,因爲這絕對適用於工具提示。 –

+0

我正在使用open()來顯示Shell,並且按照API將重點放在它上面。 setVisible(true)幫助。謝謝 –