我正在使用 SWT 构建 GUI,我正在使用网格布局。但是,当我从任何大小拖动窗口并调整大小时,它会留下大量空白空间。所以
我尝试过使用网格布局。
我正在使用 SWT 构建 GUI,我正在使用网格布局。但是,当我从任何大小拖动窗口并调整大小时,它会留下大量空白空间。所以
我尝试过使用网格布局。
看看这篇文章。以下代码来自GithubGist
public class ResponsiveDemo {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout());
shell.setBounds(20, 20, 1200, 600);
Composite parent = new Composite(shell, SWT.NONE);
parent.setLayout(new ScaleLayout(new ScaleProvider(parent)));
parent.setBackground(getSystemColor(SWT.COLOR_LIST_BACKGROUND));
configure(parent);
shell.open();
while (!shell.isDisposed()) {
if (!shell.getDisplay().readAndDispatch()) {
shell.getDisplay().sleep();
}
}
}
private static void configure(Composite parent) {
ScaleData child1 = createChild(parent, "control1", SWT.COLOR_RED);
ScaleData child2 = createChild(parent, "control2", SWT.COLOR_GREEN);
ScaleData child3 = createChild(parent, "control3", SWT.COLOR_BLUE);
ScaleData child4 = createChild(parent, "control4", SWT.COLOR_CYAN);
ScaleData child5 = createChild(parent, "control5", SWT.COLOR_YELLOW);
child1.on(Scale.SUPER_WIDE).setMargin(3, 3, 3, 3);
child2.on(Scale.SUPER_WIDE).setMargin(3, 3, 3, 3);
child3.on(Scale.SUPER_WIDE).setWidth(300).setMargin(3, 3, 3, 3);
child4.on(Scale.SUPER_WIDE).setMargin(3, 3, 3, 3);
child5.on(Scale.SUPER_WIDE).setMargin(3, 3, 3, 3);
child1.on(Scale.WIDE).setMargin(3, 3, 3, 3);
child2.on(Scale.WIDE).setMargin(3, 3, 3, 3);
child3.on(Scale.WIDE).setWidth(300).setMargin(3, 3, 3, 3);
child4.on(Scale.WIDE).tie(child5).setHeight(200).setMargin(3, 3, 3, 3);
child5.on(Scale.WIDE).setMargin(3, 3, 3, 3);
child1.on(Scale.STANDARD).setMargin(3, 3, 3, 3);
child2.on(Scale.STANDARD).tie(child3).setMargin(3, 3, 3, 3);
child3.on(Scale.STANDARD).setWidth(300).setMargin(3, 3, 3, 3);
child4.on(Scale.STANDARD).tie(child5).setMargin(3, 3, 3, 3);
child5.on(Scale.STANDARD).setMargin(3, 3, 3, 3);
child1.on(Scale.COMPACT).setMargin(3, 3, 3, 3);
child2.on(Scale.COMPACT).tie(child3).setMargin(3, 3, 3, 3);
child3.on(Scale.COMPACT).tie(child4).setSize(300, 60).setMargin(3, 3, 3, 3);
child4.on(Scale.COMPACT).tie(child5).setMargin(3, 3, 3, 3);
child5.on(Scale.COMPACT).setMargin(3, 3, 3, 3);
child1.on(Scale.SUPER_COMPACT).tie(child2).setMargin(3, 3, 3, 3);
child2.on(Scale.SUPER_COMPACT).tie(child3).setMargin(3, 3, 3, 3);
child3.on(Scale.SUPER_COMPACT).tie(child4).setHeight(60).setMargin(3, 3, 3, 3);
child4.on(Scale.SUPER_COMPACT).tie(child5).setMargin(3, 3, 3, 3);
child5.on(Scale.SUPER_COMPACT).setMargin(3, 3, 3, 3);
}
static ScaleData createChild(Composite parent, String label, int color) {
return new ScaleData(createChildControl(parent, label, color));
}
private static Control createChildControl(Composite parent, String label, int color) {
Label result = new Label(parent, SWT.WRAP);
result.setText(label);
result.setBackground(getSystemColor(color));
return result;
}
private static Color getSystemColor(int colorIndex) {
return Display.getCurrent().getSystemColor(colorIndex);
}
}