Java SWT GridLayout列重叠

Java SWT GridLayout列重叠,java,swt,grid-layout,Java,Swt,Grid Layout,代码: 之前: 之后: 说明: 当窗口最小化时(即用户逐步最小化),右栏与左栏重叠。考虑到容器的布局,我希望列不会重叠。甚至有些小部件也被隐藏了 我错过了什么?我对布局组件的不同方法持开放态度 SSCCE/大量锅炉板代码(所有元件均来自): /** * *@author ggrec * */ 公营煎饼 { 私人FormToolkit工具包; 公共静态void main(最终字符串[]args) { 新的IlovePanckes(); } 私人煎饼 { 最终显示=新显示(); 最终外壳

代码:


之前:

之后:


说明:
当窗口最小化时(即用户逐步最小化),右栏与左栏重叠。考虑到容器的布局,我希望列不会重叠。甚至有些小部件也被隐藏了

我错过了什么?我对布局组件的不同方法持开放态度


SSCCE/大量锅炉板代码(所有元件均来自):

/**
* 
*@author ggrec
*
*/
公营煎饼
{
私人FormToolkit工具包;
公共静态void main(最终字符串[]args)
{
新的IlovePanckes();
}
私人煎饼
{
最终显示=新显示();
最终外壳=新外壳(显示);
shell.setLayout(新的GridLayout(1,false));
toolkit=新表单toolkit(显示);
createWidgets(shell);
shell.open();
而(!shell.isDisposed())
{
如果(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
私有void createWidgets(最终复合父级)
{
//主要部分
最后一节=toolkit.createSection(父级,ExpandableComposite.COMPACT | ExpandableComposite.TITLE_栏);
section.setText(“主要章节”);
section.setLayout(新的GridLayout());
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,true));
//部门客户
最终复合部分client=toolkit.createComposite(部分,SWT.NONE);
sectionClient.setLayout(UIHelper.getLayoutForWidgets(新的GridLayout(2,true));
sectionClient.setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,true));
section.setClient(sectionClient);
// ---------------------  -----------------------
final Composite leftColumnComposite=toolkit.createComposite(sectionClient);
setLayout(新的GridLayout(5,false));
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,true));
//名字
最终标签Label_1=新标签(leftColumnComposite,SWT.NONE);
标签1.setText(“名称”);
final Text nameWidget=新文本(leftColumnComposite,SWT.BORDER);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false,4,1));
//损益表
最终标签Label_2=新标签(leftColumnComposite,SWT.NONE);
标签2.setText(“损益”);
最终组合pnlFilterWidget=新组合(leftColumnComposite,SWT.BORDER);
pnlFilterWidget.setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false));
//背景色
最终标签Label_3=新标签(leftColumnComposite,SWT.NONE);
标签3.setText(“Bkg颜色”);
最终按钮bkgColorSelector=新按钮(leftColumnComposite,SWT.PUSH);
setLayoutData(新网格数据(SWT.FILL、SWT.FILL、true、false));
//清除bkgColor按钮
最终按钮clearBkgColorButton=新按钮(leftColumnComposite,SWT.PUSH);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false));
// ---------------------  -----------------------
最终复合rightColumnComposite=toolkit.createComposite(sectionClient);
setLayout(新的GridLayout(5,false));
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,true));
//代码
最终标签Label_4=新标签(rightColumnComposite,SWT.NONE);
标签4.setText(“代码”);
final Text codeWidget=新文本(rightColumnComposite,SWT.BORDER);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false,4,1));
//字体样式
最终标签Label_5=新标签(rightColumnComposite,SWT.NONE);
标签_5.setText(“字体样式”);
最终组合fontStyleWidget=新组合(rightColumnComposite,SWT.BORDER);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false));
//字体颜色
最终标签Label_6=新标签(rightColumnComposite,SWT.NONE);
标签6.setText(“字体颜色”);
最终按钮fontColorSelector=新按钮(rightColumnComposite,SWT.PUSH);
setLayoutData(新的GridData(SWT.FILL,SWT.FILL,true,false));
//清除字体颜色按钮
最终按钮clearFontColorButton=新按钮(rightColumnComposite,SWT.PUSH);
clearFontColorButton.setLayoutData(新GridData(SWT.FILL,SWT.FILL,true,false));
}
}

返回将水平间距设置为10的布局。布局的其他值没有更改。好的,您是否在每个
组合
s中向
小部件
s添加任何大小限制?BWT:试着删除
UIHelper
的内容,以确保小部件没有大小限制
GridData
s在所有这些数据上,填充,填充,真,假。奇怪,你能创建一个显示这种行为的吗?添加了SSCCE。在这个例子中,我注意到我的问题发生在较小的窗口大小上——这是因为组合小部件是空的。当您使用元素填充它们时,它们知道如何调整大小。基本上,即使直接使用SWT小部件,问题仍然存在。
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));
/**
 * 
 * @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));
    }
}