2013-04-04 63 views
0

我正在開發一個基於eclipase的插件,其中創建了一個應用程序(使用SWT)。有兩類: RunAction.java它由run(),dispose()init()方法和Sample.java組成,它由具有Label小部件的示例應用程序組成。現在,當我通過將它作爲Eclipse應用程序運行來測試應用程序時,在沒有標籤小部件的情況下顯示shell。 這是什麼問題?我與他人分享了代碼。啓動Eclipse RCP應用程序時不顯示Widgets

RunAction.java

public class RunWizardAction extends Action implements IWorkbenchWindowActionDelegate { 
    /** Called when the action is created. */ 
    Sample samp=new Sample(); 
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); 


    public void init(IWorkbenchWindow window) { 

    } 

    /** Called when the action is discarded. */ 
    public void dispose() { 
    } 

    /** Called when the action is executed. */ 
    public void run(IAction action) { 


     //InvokatronWizard wizard= new InvokatronWizard(); 
     new Thread(new Runnable(){ 
     @Override 
     public void run() { 

      samp.sampleApp(shell); 

        } 
     }).start(); 
     } 
} 

Sample.java(樣本函數)

public void sampleApp(Shell shell) { 
       Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setText("Hello"); 
     JLabel lab=new JLabel("Hello World"); 
     Label username_checkout=new Label(shell, SWT.BOLD); 
     username_checkout.setText("User Name"); 
     Button button=new Button(shell,SWT.PUSH); 
     button.setText("push"); 
     shell.open(); 
     shell.setSize(270,270); 
     while (!shell1.isDisposed()) { 
      if (!display.readAndDispatch()) { 
      display.sleep(); 
      } 
     } 

    } 

回答

3

Shell沒有一個佈局。此代碼的工作對我來說:

public static void main(String[] args) 
{ 
    Display display = new Display(); 
    Shell shell = new Shell(display); 

    /* SET LAYOUT */ 
    shell.setLayout(new FillLayout()); 
    shell.setText("Hello"); 
    JLabel lab = new JLabel("Hello World"); 
    Label username_checkout = new Label(shell, SWT.BOLD); 
    username_checkout.setText("User Name"); 
    Button button = new Button(shell, SWT.PUSH); 
    button.setText("push"); 
    shell.open(); 
    shell.pack(); 
    shell.setSize(270, 270); 
    while (!shell.isDisposed()) 
    { 
     if (!display.readAndDispatch()) 
     { 
      display.sleep(); 
     } 
    } 

} 

此外,有太多Shell在你的代碼:

public void sampleApp(Shell shell) { 
    Display display = new Display(); 
    Shell shell = new Shell(display); 

所以,現在你有兩個Shell叫做shell(其中順便說一句贏得」 t編譯)...

while (!shell1.isDisposed()) 

還有第三個。那是怎麼回事?

+0

oops shell1 is typo – 2013-04-04 13:18:09

3

如果你在Eclipse之外運行,那麼你的示例應用程序就會很好,就像Baz的答案一樣。

由於您運行在Eclipse內部,因此您已經擁有一個Display和一個Shell。使用它們。

public void sampleApp(Shell shell) { 
    shell.setLayout(new FillLayout()); 
    shell.setText("Hello"); 
    JLabel lab=new JLabel("Hello World"); 
    Label username_checkout=new Label(shell, SWT.BOLD); 
    username_checkout.setText("User Name"); 
    Button button=new Button(shell,SWT.PUSH); 
    button.setText("push"); 
    shell.setSize(270,270); 
    shell.open(); 
} 
+0

thanks ... solve – 2013-04-04 13:42:29

相關問題