SWT Label/Button 未出现在复合材料中
SWT Label/Button not showing up in composite
我正在尝试将 Label
或 Button
添加到 child Composite
,但它没有按预期工作。
display = Display.getCurrent();
parentShell = display.getActiveShell();
shell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText(title);
GridLayout layout = new GridLayout(1, false);
shell.setLayout(layout);
// Content composite
contentComposite = new Composite(shell, SWT.BORDER);
GridLayout contentLayout = new GridLayout(2, true);
contentComposite.setLayout(contentLayout);
contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// Default Version
defaultVersionComposite = new Composite(contentComposite, SWT.BORDER);
defaultVersionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// Versions in Tabs
versionComposite = new Composite(contentComposite, SWT.BORDER);
versionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Button button = new Button(versionComposite, SWT.PUSH);
button.setText("Test");
现在看起来像这样。
知道那里发生了什么吗?
谢谢!
您的两个子组合没有分配给它们 Layout
。只需添加这两行:
defaultVersionComposite.setLayout(new GridLayout());
versionComposite.setLayout(new GridLayout());
我正在尝试将 Label
或 Button
添加到 child Composite
,但它没有按预期工作。
display = Display.getCurrent();
parentShell = display.getActiveShell();
shell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText(title);
GridLayout layout = new GridLayout(1, false);
shell.setLayout(layout);
// Content composite
contentComposite = new Composite(shell, SWT.BORDER);
GridLayout contentLayout = new GridLayout(2, true);
contentComposite.setLayout(contentLayout);
contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// Default Version
defaultVersionComposite = new Composite(contentComposite, SWT.BORDER);
defaultVersionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// Versions in Tabs
versionComposite = new Composite(contentComposite, SWT.BORDER);
versionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Button button = new Button(versionComposite, SWT.PUSH);
button.setText("Test");
现在看起来像这样。
知道那里发生了什么吗?
谢谢!
您的两个子组合没有分配给它们 Layout
。只需添加这两行:
defaultVersionComposite.setLayout(new GridLayout());
versionComposite.setLayout(new GridLayout());