在不添加 FormLayout 的情况下组合 GridLayout 和 FillLayout?
Combining GridLayout and FillLayout without adding FormLayout?
Java SWT提供四种标准布局类:FillLayout
、RowLayout
、GridLayout
、FormLayout
。我知道如何使用每个布局 类,但在组合布局 类.
时遇到困难
例如,我的应用程序中有一个使用 GridLayout
的屏幕。我想添加两个垂直(即 FillLayout
)布局; GridLayout
左侧的一个布局和 GridLayout
右侧的另一个布局。不幸的是,我不知道如何获得我想要的整体布局(即见底部的 ascii 艺术)。
下面的 SO link 中给出了示例答案,但我想通过添加 FormLayout 来避免过多更改代码。
can I combine SWT GridLayout and FillLayout
是否有示例代码可以让我在不使用 FormLayout 的情况下将两个 FillLayout 添加到网格布局?应如下所示(忽略最右侧 FillLayout 中粘贴错误的 ascii)。
+-------------+ +-------------------------------------------+ +--------------+
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| Fill Layout| | Grid Layout | | Fill Layout |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+-------------+ +-------------------------------------------+ +--------------+
试试下面的代码,如果您看起来与此相似,请告诉我。
我正在为 shell 使用 Absolute Layout
,我在我的应用程序中创建了 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");
}
}
输出将类似于以下内容:
Java SWT提供四种标准布局类:FillLayout
、RowLayout
、GridLayout
、FormLayout
。我知道如何使用每个布局 类,但在组合布局 类.
例如,我的应用程序中有一个使用 GridLayout
的屏幕。我想添加两个垂直(即 FillLayout
)布局; GridLayout
左侧的一个布局和 GridLayout
右侧的另一个布局。不幸的是,我不知道如何获得我想要的整体布局(即见底部的 ascii 艺术)。
下面的 SO link 中给出了示例答案,但我想通过添加 FormLayout 来避免过多更改代码。
can I combine SWT GridLayout and FillLayout
是否有示例代码可以让我在不使用 FormLayout 的情况下将两个 FillLayout 添加到网格布局?应如下所示(忽略最右侧 FillLayout 中粘贴错误的 ascii)。
+-------------+ +-------------------------------------------+ +--------------+
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| Fill Layout| | Grid Layout | | Fill Layout |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+-------------+ +-------------------------------------------+ +--------------+
试试下面的代码,如果您看起来与此相似,请告诉我。
我正在为 shell 使用 Absolute Layout
,我在我的应用程序中创建了 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");
}
}
输出将类似于以下内容: