Java SWT提供了四种标准布局类:FillLayout
,RowLayout
,GridLayout
,FormLayout
。我知道如何使用每个布局类,但在组合布局类时会很困难。
例如,我的应用程序中有一个使用GridLayout
的屏幕。我希望添加两个垂直(即FillLayout
)布局; GridLayout
左侧的一个布局和GridLayout
右侧的另一个布局。不幸的是,我无法弄清楚如何获得我想要的整体布局(即在底部看到ascii艺术)。
下面的SO链接给出了示例答案,但我想避免通过添加FormLayout来过多地更改代码。
can I combine SWT GridLayout and FillLayout
是否有示例代码允许我在不使用FormLayout的情况下将两个FillLayouts添加到网格布局?应如下所示(忽略最右侧FillLayout中粘贴严重的ascii)。
+-------------+ +-------------------------------------------+ +--------------+
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| Fill Layout| | Grid Layout | | Fill Layout |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+-------------+ +-------------------------------------------+ +--------------+
答案 0 :(得分:3)
尝试以下代码,如果您看起来与此类似,请告诉我。
我正在使用Absolute Layout
作为shell,我在我的应用程序中创建了3个复合材料,并为2个复合材料应用了Fill Layout
,为1个复合材料应用了Grid Layout
。请参阅以下代码
public class SampleWindow {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
SampleWindow window = new SampleWindow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(531, 363);
shell.setText("SWT Application");
Composite composite = new Composite(shell, SWT.BORDER);
composite.setBounds(10, 10, 131, 304);
composite.setLayout(new FillLayout(SWT.HORIZONTAL));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setText("Fill Layout");
Composite composite_1 = new Composite(shell, SWT.BORDER);
composite_1.setBounds(159, 10, 199, 304);
composite_1.setLayout(new GridLayout(3, false));
Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
lblNewLabel_1.setText("Grid Layout");
Composite composite_2 = new Composite(shell, SWT.BORDER);
composite_2.setBounds(382, 10, 123, 304);
composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));
Label lblNewLabel_2 = new Label(composite_2, SWT.NONE);
lblNewLabel_2.setText("Fill Layout");
}
}
输出类似如下:
https://www.antennahouse.com/antenna1/xml-to-xsl-fo-stylesheets/