如何设置GridData的宽度?

时间:2014-02-10 19:44:55

标签: java swt eclipse-rcp jface grid-layout

layout

我正在使用GridLayout / GridData构建用户界面。布局假设有3个部分,一个是headingComposite,一个是leftEditorComposite,一个是rightEditorComposite。但我的问题是,我不希望我的leftEditorComposite / rightEditorComposite的宽度布局被内容更改。 (就像名称文本框一样,如果输入变长,那么leftEdtiorComposite的宽度也会变长。)有没有办法将它们作为固定大小宽度?非常感谢!

    GridLayout layout = new GridLayout(2, false);
    mainComposite.setLayout(layout);

    scrolledComposite.setContent(mainComposite);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 2;
    headingComposite = new Composite(mainComposite, SWT.BORDER);
    headingComposite.setBackground(getBackground());
    headingComposite.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    leftEditorComposite = new Composite(mainComposite, SWT.BORDER);
    leftEditorComposite.setBackground(getBackground());
    leftEditorComposite.setLayoutData(data);

    data = new GridData(GridData.FILL_BOTH);
    rightEditorComposite = new Composite(mainComposite, SWT.BORDER);
    rightEditorComposite.setBackground(getBackground());
    rightEditorComposite.setLayoutData(data);

1 个答案:

答案 0 :(得分:2)

如果您知道每个合成的大小,则可以为widthHint个对象提供Composite

leftEditorComposite.widthHint = 200;

rightEditorComposite.widthHint = 200;

或者,您可以阅读此问题,希望您能得到答案: How to align two composites in a parent composite without using widthHint and heightHint