SWT GridLayout列重叠

时间:2013-08-26 08:51:42

标签: java swt grid-layout

代码:

final Composite sectionClient = toolkit.createComposite(parent, SWT.NONE);
sectionClient.setLayout(UIHelper.getLayoutForWidgets(new GridLayout(2, true)));
sectionClient.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

final Composite leftColumnComposite = toolkit.createComposite(sectionClient);
leftColumnComposite.setLayout(new GridLayout(5, false));
leftColumnComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

final Composite rightColumnComposite = toolkit.createComposite(sectionClient);
rightColumnComposite.setLayout(new GridLayout(5, false));
rightColumnComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

<小时/> 之前:
enter image description here

之后:
enter image description here


描述:
当窗口最小化时(即用户逐渐使其最小化),右列与左列重叠。鉴于容器的布局,我希望列不重叠。甚至一些小部件也会被隐藏起来。

我错过了什么?我开始采用不同的方法来布置组件。


SSCCE /许多样板代码(所有元素均来自SWT):

/**
 * 
 * @author ggrec
 *
 */
public class ILovePancakes
{
    private FormToolkit toolkit;

    public static void main(final String[] args)
    {
        new ILovePancakes();
    }

    private ILovePancakes() 
    {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));

        toolkit = new FormToolkit(display);

        createWidgets(shell);

        shell.open();
        while (!shell.isDisposed())
        {
            if ( !display.readAndDispatch() )
                display.sleep();
        }
        display.dispose();
    }

    private void createWidgets(final Composite parent)
    {
        // Main section
        final Section section = toolkit.createSection(parent, ExpandableComposite.COMPACT | ExpandableComposite.TITLE_BAR);
        section.setText("Main section");
        section.setLayout(new GridLayout());
        section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        // Section client
        final Composite sectionClient = toolkit.createComposite(section, SWT.NONE);
        sectionClient.setLayout(UIHelper.getLayoutForWidgets(new GridLayout(2, true)));
        sectionClient.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        section.setClient(sectionClient);

        // --------------------- <Left Column> -----------------------

        final Composite leftColumnComposite = toolkit.createComposite(sectionClient);
        leftColumnComposite.setLayout(new GridLayout(5, false));
        leftColumnComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        // Name
        final Label label_1 = new Label(leftColumnComposite, SWT.NONE);
        label_1.setText("Name");
        final Text nameWidget = new Text(leftColumnComposite, SWT.BORDER);
        nameWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));

        // P&L
        final Label label_2 = new Label(leftColumnComposite, SWT.NONE);
        label_2.setText("Profit and Loss");
        final Combo pnlFilterWidget = new Combo(leftColumnComposite, SWT.BORDER);
        pnlFilterWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

        // Background color
        final Label label_3 = new Label(leftColumnComposite, SWT.NONE);
        label_3.setText("Bkg color");
        final Button bkgColorSelector = new Button(leftColumnComposite, SWT.PUSH);
        bkgColorSelector.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

        // Clear bkgColor button
        final Button clearBkgColorButton = new Button(leftColumnComposite, SWT.PUSH);
        clearBkgColorButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

        // --------------------- <Right Column> -----------------------

        final Composite rightColumnComposite = toolkit.createComposite(sectionClient);
        rightColumnComposite.setLayout(new GridLayout(5, false));
        rightColumnComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        // Code 
        final Label label_4 = new Label(rightColumnComposite, SWT.NONE);
        label_4.setText("Code");
        final Text codeWidget = new Text(rightColumnComposite, SWT.BORDER);
        codeWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));

        // Font Style
        final Label label_5 = new Label(rightColumnComposite, SWT.NONE);
        label_5.setText("Font Style");
        final Combo fontStyleWidget = new Combo(rightColumnComposite, SWT.BORDER);
        fontStyleWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

        // Font color
        final Label label_6 = new Label(rightColumnComposite, SWT.NONE);
        label_6.setText("Font color");
        final Button fontColorSelector = new Button(rightColumnComposite, SWT.PUSH);
        fontColorSelector.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

        // Clear fontColor button
        final Button clearFontColorButton = new Button(rightColumnComposite, SWT.PUSH);
        clearFontColorButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    }
}

0 个答案:

没有答案