1,改完成了一个大概的样子,还要把Text改成List,可以添加,可以存到文件或者数据库中去。
public class Coordinate { private void createArea(Composite parent) { SashForm top = new SashForm(parent, SWT.HORIZONTAL);// 定义一个分割窗容器 top.setLayout(new FillLayout()); Composite right = new Composite(top, SWT.NONE); Composite left = new Composite(top, SWT.NONE); top.setWeights(new int[] {1,2}); right.setLayout(new FillLayout()); left.setLayout(new FillLayout()); new Text(right, SWT.BORDER|SWT.WRAP|SWT.V_SCROLL); SashForm x_coordinate = new SashForm(left, SWT.VERTICAL);// 定义一个分割窗容器 x_coordinate.setLayout(new FillLayout()); Composite comp1 = new Composite(x_coordinate, SWT.NONE); Composite comp2 = new Composite(x_coordinate, SWT.NONE); x_coordinate.setWeights(new int[] {1,1}); comp1.setLayout(new FillLayout()); comp2.setLayout(new FillLayout()); final Composite y1_comp = new Composite(comp1, SWT.NONE); final Composite y2_comp = new Composite(comp2, SWT.NONE); final FormData sashData1 = new FormData(),sashData2 = new FormData(); final Sash sash1,sash2; final Composite quadrant1,quadrant2,quadrant3,quadrant4; { quadrant1 = new Composite (y1_comp, SWT.NONE); sash1 = new Sash (y1_comp, SWT.VERTICAL); quadrant2 = new Composite (y1_comp, SWT.NONE); final FormLayout form = new FormLayout (); y1_comp.setLayout (form); FormData quadrant1Data = new FormData (); quadrant1Data.left = new FormAttachment (0, 0); quadrant1Data.right = new FormAttachment (sash1, 0); quadrant1Data.top = new FormAttachment (0, 0); quadrant1Data.bottom = new FormAttachment (100, 0); quadrant1.setLayoutData (quadrant1Data); int percent = 50; sashData1.left = new FormAttachment (percent, 0); sashData1.top = new FormAttachment (0, 0); sashData1.bottom = new FormAttachment (100, 0); sash1.setLayoutData (sashData1); FormData quadrant2Data = new FormData (); quadrant2Data.left = new FormAttachment (sash1, 0); quadrant2Data.right = new FormAttachment (100, 0); quadrant2Data.top = new FormAttachment (0, 0); quadrant2Data.bottom = new FormAttachment (100, 0); quadrant2.setLayoutData (quadrant2Data); } { quadrant3 = new Composite (y2_comp, SWT.NONE); sash2 = new Sash (y2_comp, SWT.VERTICAL); quadrant4 = new Composite (y2_comp, SWT.NONE); final FormLayout form = new FormLayout (); y2_comp.setLayout (form); FormData quadrant3Data = new FormData (); quadrant3Data.left = new FormAttachment (0, 0); quadrant3Data.right = new FormAttachment (sash2, 0); quadrant3Data.top = new FormAttachment (0, 0); quadrant3Data.bottom = new FormAttachment (100, 0); quadrant3.setLayoutData (quadrant3Data); int percent = 50; sashData2.left = new FormAttachment (percent, 0); sashData2.top = new FormAttachment (0, 0); sashData2.bottom = new FormAttachment (100, 0); sash2.setLayoutData (sashData2); FormData quadrant4Data = new FormData (); quadrant4Data.left = new FormAttachment (sash2, 0); quadrant4Data.right = new FormAttachment (100, 0); quadrant4Data.top = new FormAttachment (0, 0); quadrant4Data.bottom = new FormAttachment (100, 0); quadrant4.setLayoutData (quadrant4Data); } final double[] ratio = new double[]{0.5}; final int limit = 20; Listener listener = new Listener () { Rectangle sashRect,shellRect; public void handleEvent (Event e) { if(sash1 == e.widget) { sashRect = sash1.getBounds (); shellRect = y1_comp.getClientArea (); } else { sashRect = sash2.getBounds (); shellRect = y2_comp.getClientArea (); } //right限制了 left的最大值(为103)这里可以提出去,免得不断地调用,噢,不行,shell有可能变大。 //limit限制了 left的最小值(为20) int right = shellRect.width - sashRect.width - limit; e.x = Math.max (Math.min (e.x, right), limit); if (e.x != sashRect.x) { sashData2.left = new FormAttachment (0, e.x); y2_comp.layout (); sashData1.left = new FormAttachment (0, e.x); y1_comp.layout (); } if(shellRect.width != 0) { ratio[0] = (double)e.x/(shellRect.width); } } }; sash1.addListener (SWT.Selection, listener); sash2.addListener (SWT.Selection, listener); parent.addControlListener(new ControlAdapter() { Rectangle shellRect,sashRect; public void controlResized(ControlEvent e) { shellRect = y1_comp.getClientArea (); sashRect = sash1.getBounds (); if(shellRect.width != 0) { int right = (int) (ratio[0] * shellRect.width); right = Math.max (Math.min(right,shellRect.width - sashRect.width - limit), limit); sashData2.left = new FormAttachment (0, right); y2_comp.layout (); sashData1.left = new FormAttachment (0, right); y1_comp.layout (); } } }); createArea4quadrant1234(quadrant1,quadrant2,quadrant3,quadrant4); } private void createArea4quadrant1234(Composite quadrant1, Composite quadrant2, Composite quadrant3, Composite quadrant4) { quadrant1.setLayout(new FillLayout()); quadrant2.setLayout(new FillLayout()); quadrant3.setLayout(new FillLayout()); quadrant4.setLayout(new FillLayout()); Text text1 = new Text(quadrant2,SWT.BORDER | SWT.WRAP|SWT.V_SCROLL); text1.setText("quadrant1"); Text text2 = new Text(quadrant1,SWT.BORDER | SWT.WRAP|SWT.V_SCROLL); text2.setText("quadrant2"); Text text3 = new Text(quadrant3,SWT.BORDER | SWT.WRAP|SWT.V_SCROLL); text3.setText("quadrant3"); Text text4 = new Text(quadrant4,SWT.BORDER | SWT.WRAP|SWT.V_SCROLL); text4.setText("quadrant4"); text1.setToolTipText("重要紧急"); text2.setToolTipText("不重要紧急"); text3.setToolTipText("不重要不紧急"); text4.setToolTipText("重要不紧急"); text1.setText("重要紧急"); text2.setText("不重要紧急"); text3.setText("不重要不紧急"); text4.setText("重要不紧急"); } private void open() { Display display = Display.getDefault(); Shell shell = new Shell(); shell.setLayout(new FillLayout()); // ---------创建窗口中的其他界面组件------------- createArea(shell); // -----------------END------------------------ shell.setSize(800, 600); shell.layout(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } public static void main(String[] args) { new Coordinate().open(); } }
效果图: