简体   繁体   English

启动Eclipse RCP应用程序时未显示窗口小部件

[英]Widgets doesn't show up while launching Eclipse RCP Application

I'm developing a eclipase based plugin where i've created an application (using SWT). 我正在开发基于eclipase的插件,在其中创建了一个应用程序(使用SWT)。 There are two classes viz; 有两个类,即: RunAction.java which consists of run() , dispose() and init() methods and Sample.java which consists of the sample application with a Label widget. RunAction.java它由run() dispose()init()方法和Sample.java其由与标签插件的示例应用程序的。 Now, when i test the application by Running it as an Eclipse application, onlt the shell is displayed without the label widget. 现在,当我通过将其作为Eclipse应用程序运行来测试该应用程序时,显示的外壳没有标签小部件。 What is the issue? 有什么问题 I'm sharing the code. 我正在共享代码。

RunAction.java 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 (The sample function) 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();
          }
        }

    }

Your Shell doesn't have a layout. 您的Shell没有布局。 This code works for me: 该代码对我有用:

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();
        }
    }

}

Besides, there are too many Shell s in your code: 此外,您的代码中有太多Shell

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

So, now you have two Shell s called shell (which btw won't compile)... 所以,现在你有两个Shell叫做shell (顺便说一句这不会编译)...

while (!shell1.isDisposed())

And there is a third one. 还有第三个。 What's up with that? 那是怎么回事?

Your sample application would be fine if you were running outside of Eclipse like Baz's answer. 如果您像Baz的答案那样在Eclipse之外运行,那么您的示例应用程序会很好。

Since you're running inside of Eclipse, you already have a Display and a Shell. 由于您是在Eclipse中运行的,因此已经有了Display和Shell。 Use them. 使用它们。

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();
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM