固定ScrolledForm中SWT表的大小

时间:2014-05-22 08:02:37

标签: java scroll swt eclipse-rcp

我在org.eclipse.ui.forms.editor.FormPage的滚动形式中遇到了布局问题。我从它继承了我的类,并添加了两个部分和几个元素。我想要实现具有3个复合材料的底部部分,其中第一个获得固定量的空间,第二个和第三个共享其余的空间。但是我得到了以下结果:

Screenshot 1

以下是部分代码:

@Override
    protected void createFormContent(IManagedForm managedForm)
    {
        formToolkit = managedForm.getToolkit();
        ScrolledForm form = managedForm.getForm();

        Composite body = form.getBody();
        GridLayout gridLayout = new GridLayout(1, true);
        gridLayout.horizontalSpacing = 7;
        body.setLayout(gridLayout);
        formToolkit.paintBordersFor(body);

        //skipped

        // Business services left composite
        Composite compositeBSLeft = formToolkit.createComposite(compositeBSMain, SWT.NONE);
        compositeBSLeft.setLayout(new GridLayout(1, false));
        compositeBSLeft.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        formToolkit.paintBordersFor(compositeBSLeft);
                    // Business services middle composite
        Section sctnBusinessServices = toolkit.createSection(body, Section.TWISTIE | Section.TITLE_BAR);
        sctnBusinessServices.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        toolkit.paintBordersFor(sctnBusinessServices);
        sctnBusinessServices.setText("Business Services");
        sctnBusinessServices.setExpanded(true);

        //skipped

        Composite compositeBSMidBottom = formToolkit.createComposite(compositeBSMid, SWT.NONE);
        compositeBSMidBottom.setLayout(new GridLayout(1, false));
        compositeBSMidBottom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        formToolkit.paintBordersFor(compositeBSMidBottom);

        // Permission sets table
        TableViewer permissionSetsTableViewer = new TableViewer(compositeBSMidBottom,
                                                                    SWT.FULL_SELECTION | SWT.H_SCROLL
                                                                                    | SWT.V_SCROLL
                                                                                    | SWT.BORDER);
        permissionSetsTableViewer.setContentProvider(ArrayContentProvider.getInstance());

        Table permissionSetsTable = permissionSetsTableViewer.getTable();
        permissionSetsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        formToolkit.paintBordersFor(permissionSetsTable);
        permissionSetsTable.setHeaderVisible(true);
        permissionSetsTable.setLinesVisible(true);

        TableViewerColumn[] permissionSetsTableColumns = new TableViewerColumn[PERMISSIONSET_COLUMNNAMES.length];
        for (int j = 0; j < PERMISSIONSET_COLUMNNAMES.length; j++)
        {
            permissionSetsTableColumns[j] = new TableViewerColumn(permissionSetsTableViewer, SWT.NONE);
            permissionSetsTableColumns[j].getColumn().setWidth(100);
            permissionSetsTableColumns[j].getColumn().setText(PERMISSIONSET_COLUMNNAMES[j]);
        }

        permissionSetsTableViewer.setUseHashlookup(true);
        permissionSetsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
        permissionSetsTableViewer.setLabelProvider(new PermissionSetsLabelProvider());
        permissionSetsTableViewer.setInput(//blabla);

        // add the right composite and the second table

        //...
    }

如果我省略了行permissionSetsTableColumns[j].getColumn().setWidth(100);,那么我得到了所需的结果,但所有列都有零宽度。

enter image description here

我有两个想法可以解决这个问题。

1:禁止ScrolledForm水平滚动。

2:在构建布局后,为列调用setWidth()pack()

两者都有可能吗?我该如何实现呢?

另一个问题是:如何用左复合的固定宽度解决问题?因为如果我在初始化页面时放入大量文本,它会打破布局:

Screenshot 3

0 个答案:

没有答案