最近学习java,在viewform上创建了一个toolbar,在toolbar上创建两个toolitem,程序运行时怎么不显示呢?
程序代码如下:
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class Test { /**
 * Launch the application
 * @param args
 */
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(565, 445);
shell.setText("SWT Application");
//
        shell.setLayout(new FillLayout());
final ViewForm viewForm = new ViewForm(shell, SWT.NONE);
viewForm.setLayout(new FillLayout());
final ToolBar toolBar = new ToolBar(viewForm, SWT.NONE);
viewForm.setTopLeft(toolBar);


final ToolItem newItemToolItem = new ToolItem(toolBar, SWT.PUSH);
newItemToolItem.setText("取得");
final ToolItem newItemToolItem_1 = new ToolItem(toolBar, SWT.PUSH);
newItemToolItem_1.setText("清除"); final Text text = new Text(viewForm, SWT.BORDER);
viewForm.setContent(text);
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}}