工作,这就是我想实现,使用SWT:行布局不嵌套复合
对于这一点,我想使用RowLayout
嵌套的Composite
,包装复合材料的根据可用空间进行控制。下面的代码工作完美:
public class RowLayoutExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("SWT RowLayout test");
shell.setLayout(new RowLayout(SWT.HORIZONTAL));
for (int i = 0; i < 10; i++) {
new Label(shell, SWT.NONE).setText("Label " + i);
}
shell.setSize(400, 250);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
这显示(请注意下一行的最后一个标签的很好的总结 - 此外,在外壳调整,组件封装到可用的水平空间):
当我这样做,反而:
public class RowLayoutExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("SWT RowLayout test");
shell.setLayout(new RowLayout(SWT.HORIZONTAL));
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new RowLayout(SWT.HORIZONTAL));
for (int i = 0; i < 10; i++) {
new Label(comp, SWT.NONE).setText("Label " + i);
}
shell.setSize(400, 250);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
我有以下行为。如果我调整外壳的大小,标签不会包装成多行。
在下面的图片中,我们可以看到,复合材料膨胀出壳客户端的面积,而不是换行到第二行。调整外壳大小不会影响这种错误行为。
我使用下面的SWT版本:
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
<version>4.3</version>
</dependency>
那么,为什么第二种情况是不工作?此外,是否可以使用壳牌GridLayout
,但是RowLayout
是否适用于此壳牌的小孩?
无论你喜欢,你都可以混合布局。 –
好的,这也是我的猜测,但为什么嵌套的复合RowLayout不工作,而外壳的RowLayout是? – hypercube
可能与Shell RowLayout如何请求子复合来计算其大小有关。 –