我是初学RCP,以前搞WEB的,也是初学SWT的GUI设计,界面上的组件全做出来了,但是一团糟,想问一下:使用SWT中的什么布局类型才能实现这个界面?最好能详细点。任何回帖都是对我的帮助!

解决方案 »

  1.   

    GridLayout完全可以实现,你用可视化开发工具来开发很快就可以布局出来了,自己写的话太麻烦
      

  2.   

    我用的是 swt designer 但是那个好像拖动不是很方便啊 我把上面那些文字放到label里,然后分别放进4个group里,然后都用GridLayout布局,一团糟。我这么弄对不对啊
      

  3.   

    用swt designer 那最好了,你首先用GridLayout布局整个容器,然后再在上面加控件,控件有调整位置和大小的,你试试看,慢慢试试用习惯就好了。实在不行的话把你的代码发上来我弄下看
      

  4.   

       代码没什么可看的,我以前画的是我手工造的 ,恶心的很。我刚画了一副,画的当时是定位了,但是一放大窗口它还是那么大一块,你要想帮我的话,就画我贴出来那幅就可以了(从"第一步xxxx那行开始就行了")。我MSN:appleq@[防抓取]126.com ,地址删除"[防抓取]"
      

  5.   

        这个是swt designer 里面的swt/jface工程。已经可以运行了。我把4,5,6步的那些文字跟右边的“备注”和“添加”按钮对齐了,我用的是sashForm对齐他们(其实我也不知道怎么对齐)。    如果你能做成我贴图的那样也行(不用框框限制它们更好),不需要精确,我不会拿来直接用,我要研究一下你的布局实现方式。谢谢了内容过长 分2部分
    package ddd;import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.SashForm;
    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.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.Text;
    import java.util.ArrayList;
    import java.util.Iterator;import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.ToolBar;
    import org.eclipse.swt.widgets.ToolItem;
    import org.eclipse.jface.action.IToolBarManager;
    import org.eclipse.jface.viewers.ISelection;
    import org.eclipse.jface.viewers.ISelectionChangedListener;
    import org.eclipse.jface.viewers.ISelectionProvider;
    import org.eclipse.jface.viewers.ListViewer;
    import org.eclipse.jface.viewers.SelectionChangedEvent;
    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.SashForm;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.MouseTrackAdapter;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.events.SelectionListener;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.ui.part.ViewPart;
      

  6.   

    public class ttt
    { protected Shell shell;
    private Table table_1;
    private Text text_4;
    private Text text_1;
    private Text text_3;
    private Text text_2;
    private Table table;
    private ISelection selection;
    ArrayList myListeners = new ArrayList();
    private Group group_1; /**
     * Launch the application
     * @param args
     */
    public static void main(String[] args)
    {
    try
    {
    ttt window = new ttt();
    window.open();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    } /**
     * Open the window
     */
    public void open()
    {
    final Display display = Display.getDefault();
    createContents();
    shell.open();
    shell.layout();
    while (!shell.isDisposed())
    {
    if (!display.readAndDispatch())
    display.sleep();
    }
    } /**
     * Create contents of the window
     */
    protected void createContents()
    {
    shell = new Shell();
    shell.setSize(500, 375);
    shell.setText("SWT Application");
    //
    shell.setLayout(new FillLayout());


    // TODO Auto-generated method stub
    group_1 = new Group(shell, SWT.NO_RADIO_GROUP);
    final GridLayout gridLayout = new GridLayout();
    group_1.setLayout(gridLayout); final Group group = new Group(group_1, SWT.NONE);
    group.setLayoutData(new GridData(480, 170));
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.numColumns = 4;
    group.setLayout(gridLayout_1); final Label label_1_1 = new Label(group, SWT.NONE);
    label_1_1.setLayoutData(new GridData(106, 15));
    label_1_1.setText("第1步"); final Label label = new Label(group, SWT.NONE);
    label.setLayoutData(new GridData(106, 18));
    label.setText("日期"); text_3 = new Text(group, SWT.BORDER);
    final GridData gd_text_2 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gd_text_2.widthHint = 107;
    text_3.setLayoutData(gd_text_2);
    new Label(group, SWT.NONE); final Label label_1_2 = new Label(group, SWT.NONE);
    label_1_2.setLayoutData(new GridData(106, 15));
    label_1_2.setText("第1步"); final Label label_1 = new Label(group, SWT.NONE);
    label_1.setLayoutData(new GridData(106, 15));
    label_1.setText("项目"); text_1 = new Text(group, SWT.BORDER);
    final GridData gd_text_2_1 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gd_text_2_1.widthHint = 105;
    text_1.setLayoutData(gd_text_2_1); final Button button = new Button(group, SWT.NONE);
    button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    button.setText("编辑"); final Label label_1_3 = new Label(group, SWT.NONE);
    label_1_3.setLayoutData(new GridData(189, 15));
    label_1_3.setText("第1步"); final Label label_2 = new Label(group, SWT.NONE);
    label_2.setLayoutData(new GridData(115, 15));
    label_2.setText("金额"); text_4 = new Text(group, SWT.BORDER);
    final GridData gd_text_2_2 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gd_text_2_2.widthHint = 106;
    text_4.setLayoutData(gd_text_2_2);
    new Label(group, SWT.NONE); final Group group_2 = new Group(group, SWT.NONE);
    group_2.setLayoutData(new GridData(188, 76));
    group_2.setLayout(new GridLayout()); final Label label_1_3_3 = new Label(group_2, SWT.NONE);
    label_1_3_3.setLayoutData(new GridData(106, 15));
    label_1_3_3.setText("第1步"); final Label label_1_3_1 = new Label(group_2, SWT.NONE);
    label_1_3_1.setLayoutData(new GridData(106, 15));
    label_1_3_1.setText("第1步"); final Label label_1_3_2 = new Label(group_2, SWT.NONE);
    label_1_3_2.setLayoutData(new GridData(106, 15));
    label_1_3_2.setText("第1步"); final SashForm sashForm_1 = new SashForm(group, SWT.NONE);
    sashForm_1.setLayoutData(new GridData(104, 19)); final Label label_2_1 = new Label(sashForm_1, SWT.NONE);
    label_2_1.setText("备注");
    text_2 = new Text(group, SWT.BORDER);
    final GridData gd_text_1 = new GridData(SWT.LEFT, SWT.CENTER, true, false);
    gd_text_1.heightHint = 50;
    gd_text_1.widthHint = 191;
    text_2.setLayoutData(gd_text_1); final Button button_1 = new Button(group, SWT.NONE);
    button_1.setText("添加"); final TableViewer tableViewer = new TableViewer(group_1, SWT.BORDER);
    table_1 = tableViewer.getTable();
    table_1.setLinesVisible(true);
    table_1.setHeaderVisible(true);
    final GridData gd_table_1 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_table_1.heightHint = 87;
    table_1.setLayoutData(gd_table_1); final TableColumn newColumnTableColumn = new TableColumn(table_1, SWT.NONE);
    newColumnTableColumn.setWidth(100);
    newColumnTableColumn.setText("New column"); final TableColumn newColumnTableColumn_1 = new TableColumn(table_1, SWT.NONE);
    newColumnTableColumn_1.setWidth(100);
    newColumnTableColumn_1.setText("New column"); final TableColumn newColumnTableColumn_2 = new TableColumn(table_1, SWT.NONE);
    newColumnTableColumn_2.setWidth(100);
    newColumnTableColumn_2.setText("New column"); final TableColumn newColumnTableColumn_3 = new TableColumn(table_1, SWT.NONE);
    newColumnTableColumn_3.setWidth(100);
    newColumnTableColumn_3.setText("New column"); final TableColumn newColumnTableColumn_4 = new TableColumn(table_1, SWT.NONE);
    newColumnTableColumn_4.setWidth(100);
    newColumnTableColumn_4.setText("New column"); final Group group_3 = new Group(group_1, SWT.NONE);
    final GridData gd_group_3 = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    gd_group_3.heightHint = 39;
    gd_group_3.widthHint = 97;
    group_3.setLayoutData(gd_group_3);
    final GridLayout gridLayout_2 = new GridLayout();
    gridLayout_2.numColumns = 2;
    group_3.setLayout(gridLayout_2); final Button button_2 = new Button(group_3, SWT.NONE);
    button_2.setAlignment(SWT.RIGHT);
    button_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    button_2.setText("删除"); final Button button_1_1 = new Button(group_3, SWT.NONE);
    button_1_1.setAlignment(SWT.RIGHT);
    button_1_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    button_1_1.setText("完成");


    }}
      

  7.   

    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.SashForm;
    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.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.Text;
    import java.util.ArrayList;
    import java.util.Iterator;import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.ToolBar;
    import org.eclipse.swt.widgets.ToolItem;
    import org.eclipse.jface.action.IToolBarManager;
    import org.eclipse.jface.viewers.ISelection;
    import org.eclipse.jface.viewers.ISelectionChangedListener;
    import org.eclipse.jface.viewers.ISelectionProvider;
    import org.eclipse.jface.viewers.ListViewer;
    import org.eclipse.jface.viewers.SelectionChangedEvent;
    import org.eclipse.jface.viewers.TableViewer;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.SashForm;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.MouseTrackAdapter;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.events.SelectionListener;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Group;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.ui.part.ViewPart;public class ttt
    {    protected Shell shell;
        private Table table_1;
        private Text text_4;
        private Text text_1;
        private Text text_3;
        private Text text_2;
        private Table table;
        private ISelection selection;
        ArrayList myListeners = new ArrayList();
        private Group group_1;    /**
         * Launch the application
         * @param args
         */
        public static void main(String[] args)
        {
            try
            {
                ttt window = new ttt();
                window.open();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }    /**
         * Open the window
         */
        public void open()
        {
            final Display display = Display.getDefault();
            createContents();
            shell.open();
            shell.layout();
            while (!shell.isDisposed())
            {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }    /**
         * Create contents of the window
         */
        protected void createContents()
        {
            shell = new Shell();
            shell.setSize(500, 375);
            shell.setText("SWT Application");
            //
            shell.setLayout(new FillLayout());
            
            
            // TODO Auto-generated method stub
            group_1 = new Group(shell, SWT.NO_RADIO_GROUP);
            final GridLayout gridLayout = new GridLayout();
            group_1.setLayout(gridLayout);        final Group group = new Group(group_1, SWT.NONE);
            final GridData gd_group = new GridData(SWT.FILL, SWT.CENTER, false, false);
            gd_group.heightHint = 170;
            gd_group.widthHint = 480;
            group.setLayoutData(gd_group);
            final GridLayout gridLayout_1 = new GridLayout();
            gridLayout_1.numColumns = 4;
            group.setLayout(gridLayout_1);        final Label label_1_1 = new Label(group, SWT.NONE);
            label_1_1.setLayoutData(new GridData(106, 15));
            label_1_1.setText("第1步");        final Label label = new Label(group, SWT.NONE);
            label.setLayoutData(new GridData(106, 18));
            label.setText("日期");        text_3 = new Text(group, SWT.BORDER);
            final GridData gd_text_2 = new GridData(SWT.FILL, SWT.CENTER, true, false);
            gd_text_2.widthHint = 107;
            text_3.setLayoutData(gd_text_2);
            new Label(group, SWT.NONE);        final Label label_1_2 = new Label(group, SWT.NONE);
            label_1_2.setLayoutData(new GridData(106, 15));
            label_1_2.setText("第1步");        final Label label_1 = new Label(group, SWT.NONE);
            label_1.setLayoutData(new GridData(106, 15));
            label_1.setText("项目");        text_1 = new Text(group, SWT.BORDER);
            final GridData gd_text_2_1 = new GridData(SWT.FILL, SWT.CENTER, true, false);
            gd_text_2_1.widthHint = 105;
            text_1.setLayoutData(gd_text_2_1);
      

  8.   

            final Button button = new Button(group, SWT.NONE);
            button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
            button.setText("编辑");        final Label label_1_3 = new Label(group, SWT.NONE);
            label_1_3.setLayoutData(new GridData(189, 15));
            label_1_3.setText("第1步");        final Label label_2 = new Label(group, SWT.NONE);
            label_2.setLayoutData(new GridData(115, 15));
            label_2.setText("金额");        text_4 = new Text(group, SWT.BORDER);
            final GridData gd_text_2_2 = new GridData(SWT.FILL, SWT.CENTER, true, false);
            gd_text_2_2.widthHint = 106;
            text_4.setLayoutData(gd_text_2_2);
            new Label(group, SWT.NONE);        final Group group_2 = new Group(group, SWT.NONE);
            group_2.setLayoutData(new GridData(188, 76));
            group_2.setLayout(new GridLayout());        final Label label_1_3_3 = new Label(group_2, SWT.NONE);
            label_1_3_3.setLayoutData(new GridData(106, 15));
            label_1_3_3.setText("第1步");        final Label label_1_3_1 = new Label(group_2, SWT.NONE);
            label_1_3_1.setLayoutData(new GridData(106, 15));
            label_1_3_1.setText("第1步");        final Label label_1_3_2 = new Label(group_2, SWT.NONE);
            label_1_3_2.setLayoutData(new GridData(106, 15));
            label_1_3_2.setText("第1步");        final SashForm sashForm_1 = new SashForm(group, SWT.NONE);
            sashForm_1.setLayoutData(new GridData(104, 19));        final Label label_2_1 = new Label(sashForm_1, SWT.NONE);
            label_2_1.setText("备注");
                    text_2 = new Text(group, SWT.BORDER);
            final GridData gd_text_1 = new GridData(SWT.FILL, SWT.CENTER, true, false);
            gd_text_1.heightHint = 50;
            gd_text_1.widthHint = 191;
            text_2.setLayoutData(gd_text_1);        final Button button_1 = new Button(group, SWT.NONE);
            button_1.setText("添加");        final TableViewer tableViewer = new TableViewer(group_1, SWT.BORDER);
            table_1 = tableViewer.getTable();
            table_1.setLinesVisible(true);
            table_1.setHeaderVisible(true);
            final GridData gd_table_1 = new GridData(SWT.FILL, SWT.FILL, true, true);
            gd_table_1.heightHint = 87;
            table_1.setLayoutData(gd_table_1);        final TableColumn newColumnTableColumn = new TableColumn(table_1, SWT.NONE);
            newColumnTableColumn.setWidth(100);
            newColumnTableColumn.setText("New column");        final TableColumn newColumnTableColumn_1 = new TableColumn(table_1, SWT.NONE);
            newColumnTableColumn_1.setWidth(100);
            newColumnTableColumn_1.setText("New column");        final TableColumn newColumnTableColumn_2 = new TableColumn(table_1, SWT.NONE);
            newColumnTableColumn_2.setWidth(100);
            newColumnTableColumn_2.setText("New column");        final TableColumn newColumnTableColumn_3 = new TableColumn(table_1, SWT.NONE);
            newColumnTableColumn_3.setWidth(100);
            newColumnTableColumn_3.setText("New column");        final TableColumn newColumnTableColumn_4 = new TableColumn(table_1, SWT.NONE);
            newColumnTableColumn_4.setWidth(100);
            newColumnTableColumn_4.setText("New column");        final Group group_3 = new Group(group_1, SWT.NONE);
            final GridData gd_group_3 = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
            gd_group_3.heightHint = 39;
            gd_group_3.widthHint = 97;
            group_3.setLayoutData(gd_group_3);
            final GridLayout gridLayout_2 = new GridLayout();
            gridLayout_2.numColumns = 2;
            group_3.setLayout(gridLayout_2);        final Button button_2 = new Button(group_3, SWT.NONE);
            button_2.setAlignment(SWT.RIGHT);
            button_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
            button_2.setText("删除");        final Button button_1_1 = new Button(group_3, SWT.NONE);
            button_1_1.setAlignment(SWT.RIGHT);
            button_1_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
            button_1_1.setText("完成");
            
            
        }}
      

  9.   

    我大致改了一下,不知是不是你想要的,我给个建议最好一开始就用GridLayout来布局每一个控件,不要在中间乱修改或者随意拖动那样容易混乱,用desigen做还是很方便的,用习惯了就好