swt布局
package com.iteye.niewj.layout;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.SashForm;import org.eclipse.swt.custom.ScrolledComposite;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.DateTime;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.List;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;public class ShowStackLayout {public void open() {// 1.主shellDisplay display = new Display();Shell shell = new Shell(display, SWT.MAX | SWT.MIN | SWT.CLOSE);shell.setBounds(10, 100, 600, 600);shell.setText("栈式布局");shell.setLayout(new FillLayout());// @@@@@@@@@@@@@// 2.大窗口分左右分窗SashForm sashForm = new SashForm(shell, SWT.BORDER);// 2.1 左分窗的listfinal List selectList = new List(sashForm, SWT.BORDER);/** @这里修改 */selectList.add("Http");selectList.add("Dns");selectList.add("IcmpPing");selectList.add("Ftp");selectList.setData("Http", "HttpTest");selectList.setData("Dns", "DnsTest");selectList.setData("IcmpPing", "IcmpPingTest");selectList.setData("Ftp", "FtpTest");selectList.select(new int[] { 0 });// 两个事件之一:list双击事件// selectList.addMouseListener(new// MyListSelectionListener(selectList,stack));//自定义// 2.2 右分窗的的内容Composite contentCmps = new Composite(sashForm, SWT.BORDER);contentCmps.setBounds(1, 1, 360, 410);// 2.2.1 时间控件Label begin = new Label(contentCmps, SWT.NONE);begin.setText("开始时间 ");Text beginTime = new Text(contentCmps, SWT.BORDER);begin.setBounds(10, 10, 60, 25);beginTime.setLayoutData(new GridData(120, 1));DateTime dt_date = new DateTime(contentCmps, SWT.DATE | SWT.H_SCROLL| SWT.V_SCROLL);DateTime dt_time = new DateTime(contentCmps, SWT.TIME | SWT.LONG| SWT.H_SCROLL | SWT.V_SCROLL);dt_date.setBounds(70, 10, 120, 25);dt_time.setBounds(250, 10, 120, 25);Label end = new Label(contentCmps, SWT.NONE);end.setText("结束时间");end.setBounds(10, 45, 60, 25);Text endtime = new Text(contentCmps, SWT.BORDER);endtime.setLayoutData(new GridData(120, -1));DateTime dt_date_end = new DateTime(contentCmps, SWT.DATE| SWT.H_SCROLL | SWT.V_SCROLL);DateTime dt_time_end = new DateTime(contentCmps, SWT.TIME | SWT.LONG| SWT.H_SCROLL | SWT.V_SCROLL);dt_date_end.setBounds(70, 45, 120, 25);dt_time_end.setBounds(250, 45, 120, 25);/* 2.滚动条面板 */// 式样为深陷型、带水平滚动条、带垂直滚动条ScrolledComposite scrolledComposite = new ScrolledComposite(contentCmps, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);scrolledComposite.setBounds(70, 80, 300, 350);// 面板Composite,用此面板来容纳其他的组件Composite composite = new Composite(scrolledComposite, SWT.NONE);composite.setSize(350, 400);GridLayout gLayout = new GridLayout(2, true);gLayout.horizontalSpacing = 30;composite.setLayout(gLayout);// 设置composite被scrolledComposite控制(指滚动条拖动)scrolledComposite.setContent(composite);/* 3.底排两个按钮 */Button button = new Button(contentCmps, SWT.NONE);button.setText("确定修改");button.setBounds(70, 450, 100, 25);Button addTime = new Button(contentCmps, SWT.NONE);addTime.setText("增加时间段...");final int x_index = composite.getBounds().x + 30;Listener listener = new Listener() {public void handleEvent(Event event) {Shell shell = new Shell();// addResult(shell,x_index);}};addTime.setBounds(220, 450, 100, 25);addTime.addListener(SWT.Selection, listener);{Label name = new Label(composite, SWT.RIGHT);name.setText("名称 ");Label value = new Label(composite, SWT.RIGHT);value.setText("值");// new TcpPingView(composite);}composite.pack();sashForm.setWeights(new int[] { 1, 4 });shell.layout();shell.open();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}};private void init(Composite sh) {}/** * @author nKF61564 * @since 2012-6-5 */public static void main(String[] args) {new ShowStackLayout().open();}}?