2 つの複合サイトを垂直に配置できるレイアウトが 1 つ必要です。最初のコンポジットの高さは、2 番目のコンポジットよりも大きくする必要があります。null レイアウトは使用できません。これにはレイアウトマネージャーを使用する必要があります。シェルのサイズを変更するたびに、コンポジットもサイズ変更する必要があります。これを管理できるのはどのレイアウトですか? 添付のスクリーンショットをご覧ください。これは私が必要とする出力の種類です.![私がここに添付した画像を誰か見ることができますか? 私は見ることができません。
スクリーンショットが表示されない理由がわかりません。以下のコードを追加しました。してみてください。
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();
}
}
}