我需要一种布局,其中 2 个 compsites 可以垂直坐在一起。第一个复合材料的高度应该比第二个大。我不能使用空布局。我必须为此使用一些布局管理器。每当我调整外壳大小时,复合材料也应该调整大小。哪个布局可以管理这个?请参阅随附的屏幕截图。这是我需要的那种输出。![有人可以看到我附在此处的图像吗?我看不见。
我不知道为什么没有出现屏幕截图。我在下面添加了代码。请试试。
package views;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
public class NewComposite extends org.eclipse.swt.widgets.Composite {
private Composite composite1;
private Composite composite2;
/**
* Auto-generated main method to display this
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void main(String[] args) {
showGUI();
}
/**
* Overriding checkSubclass allows this class to extend org.eclipse.swt.widgets.Composite
*/
protected void checkSubclass() {
}
/**
* Auto-generated method to display this
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void showGUI() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
NewComposite inst = new NewComposite(shell, SWT.NULL);
Point size = inst.getSize();
shell.setLayout(new FillLayout());
shell.layout();
if(size.x == 0 && size.y == 0) {
inst.pack();
shell.pack();
} else {
Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
shell.setSize(shellBounds.width, shellBounds.height);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public NewComposite(org.eclipse.swt.widgets.Composite parent, int style) {
super(parent, style);
initGUI();
}
private void initGUI() {
try {
this.setLayout(null);
this.setSize(492, 304);
{
composite1 = new Composite(this, SWT.BORDER_SOLID);
GridLayout composite1Layout = new GridLayout();
composite1Layout.makeColumnsEqualWidth = true;
composite1.setLayout(composite1Layout);
composite1.setBounds(0, 0, 492, 232);
composite1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
}
{
composite2 = new Composite(this, SWT.BORDER_SOLID);
GridLayout composite2Layout = new GridLayout();
composite2Layout.makeColumnsEqualWidth = true;
composite2.setLayout(composite2Layout);
composite2.setBounds(0, 232, 492, 72);
composite2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
}
this.layout();
} catch (Exception e) {
e.printStackTrace();
}
}
}