我正在使用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);
答案 0 :(得分:2)
如果您知道每个合成的大小,则可以为widthHint
个对象提供Composite
。
leftEditorComposite.widthHint = 200;
和
rightEditorComposite.widthHint = 200;
或者,您可以阅读此问题,希望您能得到答案: How to align two composites in a parent composite without using widthHint and heightHint