package swt; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class HelloSwt_01 { public static void main(String[] args) { //负责和操作系统交互,如读取底层事件等 Display display= new Display(); //窗口 final Shell topShell= new Shell(display,SWT.SHELL_TRIM|SWT.BORDER); topShell.setText( "这是一个窗口" ); topShell.setSize( 800 , 500 ); topShell.setLayout( new FillLayout()); //不设置布局不显示 // topShell.setLayout(new GridLayout()); Text text= new Text(topShell,SWT.BORDER); text.setText( "文本框" ); text.selectAll(); // text.copy(); // text.paste(); // text.clearSelection(); new Text(topShell, SWT.SINGLE|SWT.NONE).pack(); // new Text(topShell, SWT.MULTI|SWT.WRAP).setLayoutData(new GridData(GridData.FILL_BOTH)); Button button= new org.eclipse.swt.widgets.Button(topShell, SWT.BORDER); button.setText( "创建子窗口" ); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { creatMuti(topShell, "子窗口" ); } }); button.pack(); text.pack(); // topShell.pack(); topShell.open(); // Shell dialogShell=new Shell(topShell,SWT.SHELL_TRIM|SWT.PRIMARY_MODAL); // dialogShell.setSize(200, 100); // dialogShell.pack(); // dialogShell.open(); while (!topShell.isDisposed()){ if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } public static Shell creatMuti(Shell parent,String name){ Shell childShell= new Shell(parent, SWT.DIALOG_TRIM); childShell.setText(name); childShell.setSize( 200 , 200 ); childShell.open(); return childShell; } } |