SWT GridLayout columns overlap

巧了我就是萌 提交于 2021-01-27 10:42:34

问题


Code:

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));


Before:
enter image description here

After:
enter image description here


Description:
When window is minimized (i.e. user progressively minimizes it), the right column overlaps the left column. Given the layout of the containers, I would expect the columns not to overlap. Even some of the widgets become hidden.

What am I missing? I'm opened to a different approach on laying out the components.


SSCCE / Lots of boiler-plate code (all elements are from 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));
    }
}

来源:https://stackoverflow.com/questions/18440195/swt-gridlayout-columns-overlap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!