我是开发Eclipse插件的新手,我已经设法做了很多工作。这是我被卡住的地方。我有一个带按钮的视图。当用户点击按钮时我想要打开一个新窗口(窗口是带有文本区域,按钮和其他SWT小部件的表单)。我已经完成了窗口的创建。
在编译应用程序之后,我得到了eclipse工作台的新实例(正如预期的那样),但是当我打开视图并单击按钮时,窗口不显示。这是窗口代码段:
public class NewWindow {
private Display display;
private Shell shell;
public NewWindow(){
this.display = new Display();
shell = new Shell(displaySWT.TITLE | SWT.MIN | SWT.CLOSE);
shell.setText("fffffffffffff");
// additional code here
...
...
shell.open();
this.shellSleep(); // this methode is implemented in my code
}
这是调用此类的代码段:
... ...
this.btnCreateNewQuery.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e){
}
public void widgetSelected(SelectionEvent e){ NewWindow b = new NewWindow();
}
});
... ...
我不明白为什么窗户不显示。我试图解决它,但还没有找到任何东西。我在这个网站上看了一些东西,但我不明白他们的意思。这是链接: How do I get the workbench window to open a modal dialog in an Eclipse based project?
答案 0 :(得分:3)
public NewWindow() {
this.display = PlatformUI.getWorkbench().getDisplay();
shell = new Shell(display, SWT.TITLE | SWT.MIN | SWT.CLOSE);
shell.setText("fffffffffffff");
// additional code here
...
...
shell.open();
this.shellSleep(); // this methode is implemented in my code
}
另外,您可以关闭显示变量,只需将null传递给Shell构造函数。
答案 1 :(得分:0)
我认为您不想创建新的Shell。而是将父Shell传递到新类中。我发现为新窗口扩展一个Dialog类(或Dialog本身)更容易。然后在构造函数中,您可以调用super(Shell父级)为您初始化所有环境/ GUI内容,然后您可以按照您希望的方式布局Dialog区域。然后打开新窗口,执行dialog.open()。