Java 小部件不';启动EclipseRCP应用程序时不显示
我正在开发一个基于eclipase的插件,在这里我创建了一个应用程序(使用SWT)。有两类,即:Java 小部件不';启动EclipseRCP应用程序时不显示,java,eclipse,eclipse-plugin,swt,eclipse-rcp,Java,Eclipse,Eclipse Plugin,Swt,Eclipse Rcp,我正在开发一个基于eclipase的插件,在这里我创建了一个应用程序(使用SWT)。有两类,即:RunAction.java包含run()、dispose()和init()方法和Sample.java包含带有标签小部件的示例应用程序。现在,当我通过将应用程序作为Eclipse应用程序运行来测试该应用程序时,只会显示没有标签小部件的shell问题出在哪里?我正在分享代码 RunAction.java java(示例函数) 您的Shell没有布局。此代码适用于我: public static vo
RunAction.java
包含run()
、dispose()
和init()
方法和Sample.java
包含带有标签小部件的示例应用程序。现在,当我通过将应用程序作为Eclipse应用程序运行来测试该应用程序时,只会显示没有标签小部件的shell问题出在哪里?我正在分享代码
RunAction.java
java(示例函数)
您的
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
s:
public void sampleApp(Shell shell) {
Display display = new Display();
Shell shell = new Shell(display);
因此,现在有两个名为Shell
的Shell
(顺便说一句,它不会编译)
还有第三个。这是怎么回事?您的
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
s:
public void sampleApp(Shell shell) {
Display display = new Display();
Shell shell = new Shell(display);
因此,现在有两个名为Shell
的Shell
(顺便说一句,它不会编译)
还有第三个。这是怎么回事?如果您像Baz的答案一样在Eclipse之外运行,那么您的示例应用程序就可以了 因为您在Eclipse内部运行,所以已经有了一个显示器和一个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();
}
如果您像Baz的答案一样在Eclipse之外运行,那么您的示例应用程序就可以了 因为您在Eclipse内部运行,所以已经有了一个显示器和一个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();
}