java - 启动 Eclipse RCP 应用程序时小部件不显示

标签 java eclipse eclipse-plugin swt eclipse-rcp

我正在开发一个基于 eclipase 的插件,我在其中创建了一个应用程序(使用 SWT)。有两类: RunAction.javarun()dispose()init() 方法和 组成Sample.java 由带有 Label 小部件的示例应用程序组成。现在,当我通过将应用程序作为 Eclipse 应用程序运行来测试该应用程序时,仅显示 shell,而没有标签小部件。 问题是什么?我正在共享代码。

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)

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

    }

最佳答案

您的 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);

所以,现在你有两个名为 shellShell(顺便说一句,它不会编译)...

while (!shell1.isDisposed())

还有第三个。这是怎么回事?

关于java - 启动 Eclipse RCP 应用程序时小部件不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15809786/

相关文章:

Java 网络启动 : how to vary heap memory request in jnlp depending on what client can manage?

java - Apache Commons Lang3 与 Apache Commons Text 之间有什么区别?

java - Eclipse Egit 自动提交/推送

java - 如何从 Eclipse Marketplace 安装我的 Eclipse 插件?

java - 如何将 (.JAR) 文件转换为 UML?

javascript - 使用hibernate spring mvc检测数据库中的行

java - mockito 和 jetty-client : receiving NullPointerException when start() and stop() methods are invoked

java - eclipse:如何让 "link with editor"在窗口之间工作?

java - 切换屏幕javafx eclipse

maven - 无法计算构建计划:插件org.apache.maven.plugins:maven-jar-plugin:2.3.2或其依赖项之一无法解析