我正在尝试运行 WindowBuilder 来构建一些 SWT 应用程序。但是,当我单击“设计”选项卡时,出现此错误:
我使用的产生上述错误的代码只是启动新项目时的基本默认代码。当我尝试运行在 Java 中执行时确实运行的实际 SWT 项目时,会发生相同的错误:
这是代码:
package ch2;
import org.eclipse.swt.*;
public class HelloSWT {
public static void main(String[] args) {
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello World");
shell.setBounds(100, 100, 200, 50);
//Layout
RowLayout rowLay = new RowLayout(SWT.HORIZONTAL);
rowLay.justify = true;
rowLay.marginTop = 20;
rowLay.marginBottom = 20;
//Form Layout
FormData formData = new FormData();
formData.right = new FormAttachment(100, -5);
formData.bottom = new FormAttachment(100, -5);
//shell.setLayout(new FillLayout(SWT.VERTICAL));
shell.setLayout(rowLay);
final Label label = new Label(shell, SWT.CENTER);
label.setText("Hello Inside World");
org.eclipse.swt.graphics.Color red = new org.eclipse.swt.graphics.Color(display, 255, 0, 0);
label.setForeground(red);
//Button
final Button button = new Button(shell, 0);
button.setText("A Button");
Image img = new Image(display, "C:\\Users\\ra_stein\\Pictures\\koala.png");
button.setImage(img);
button.setForeground(red);
button.pack();
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
button.setText("A clicked Button");
label.setText("Hello Yourself");
}
});
Text txt = new Text(shell, SWT.SINGLE);
txt.setText("Text Object");
txt.addVerifyListener(new VerifyListener(){
public void verifyText(VerifyEvent event){
event.doit = event.text.length() == 1 || Character.isDigit(event.text.charAt(0)); //set doit to true if the length of the event.text (the text I want to put in) is exactly one OR the the first character is a digit.
}
}
);
//Table
final Table table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn column1 = new TableColumn(table, SWT.NULL);
column1.setText("Name");
column1.pack();
TableColumn column2 = new TableColumn(table, SWT.NULL);
column2.setText("Age");
column2.pack();
TableItem item1 = new TableItem(table, SWT.NULL);
item1.setText(new String[] {"Dan", "43"});
TableItem item2 = new TableItem(table, SWT.NULL);
item2.setText(new String[] {"John", "23"});
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event){
TableItem[] selected = table.getSelection();
if (selected.length > 0){
System.out.println("Name: " + selected[0].getText(0));
System.out.println("Age: " + selected[0].getText(1));
}
}
});
//Tab Folder
final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL);
tabItem1.setText("Tab 1");
TabItem tabItem2 = new TabItem(tabFolder, SWT.NULL);
tabItem2.setText("Tab 2");
Composite compo = new Composite(tabFolder, SWT.NULL);
tabItem2.setControl(compo);
//Text helloText = new Text(shell, SWT.CENTER);
//helloText.setText("Hello SWT");
//helloText.pack();
shell.pack();
shell.open();
while(!shell.isDisposed()){
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
这是错误: