如何使用固定在所有显示屏尺寸上的SWT设计如下图所示?

时间:2018-10-24 05:56:07

标签: eclipse swt e4

我正在尝试使用swt设计如下图所示的图像。我在需要提供宽度和高度的FormLayout中为所有屏幕尺寸固定了宽度和高度。但我想根据屏幕尺寸调整大小。如何实施?

image

1 个答案:

答案 0 :(得分:1)

您可以使用足够的中间复合材料使用GridLayout进行此操作:

// Assumes 'parent' has FillLayout which will be the case for an e4 part

Composite outer = new Composite(parent, SWT.NONE);

outer.setLayout(new GridLayout());

Composite intermediate = new Composite(outer, SWT.NONE);
intermediate.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

intermediate.setLayout(new GridLayout());

Composite inner = new Composite(intermediate, SWT.NONE);
inner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));

inner.setLayout(new GridLayout(4, false));

Label label1 = new Label(inner, SWT.LEAD);
label1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
label1.setText("TopLevelPath");

Text text1 = new Text(inner, SWT.SINGLE | SWT.BORDER);
text1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

Label endLabel = new Label(inner, SWT.PUSH);
endLabel.setText("but1");

endLabel = new Label(inner, SWT.PUSH);
endLabel.setText("but2");

Label label2 = new Label(inner, SWT.LEAD);
label2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
label2.setText("Alt TopLevelPath (optional)");

Text text2 = new Text(inner, SWT.SINGLE | SWT.BORDER);
text2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));