0

我正在尝试为 Eclipse 编辑器设计一个表单并遇到一些问题。

这个想法是有一个包含 2 个部分的页面 - 左侧部分包含一个表格和两个按钮。该表应与该部分的顶部对齐并向右扩展至底部。我希望按钮位于该部分中表格的右侧,每个按钮在另一个下方,并与表格顶部对齐。

有谁知道我需要为 GridLayouts 设置哪些设置才能完成这项工作?我已经尝试了所有我能想到的组合,但没有运气。

我能得到的最接近的结果是页面底部的第二个按钮。

到目前为止,这是我的代码的摘录:-

Section section = toolkit.createSection(sashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.NO_TITLE_FOCUS_BOX);
section.setText("All Items");

Composite client = toolkit.createComposite(section);
section.setClient(client);

client.setLayout(new GridLayout(2, false));

Table table = toolkit.createTable(client, SWT.NULL);
table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));

TableViewer viewer = new TableViewer(table);

Button addButton = toolkit.createButton(client, "Add", SWT.PUSH);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));

Button removeButton = toolkit.createButton(client, "Remove", SWT.PUSH);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
4

1 回答 1

1

看看SWT 布局教程,它有一个关于 GridLayout 的好部分。

您将希望使用GridData.verticalSpanfor 表使其覆盖两行。那应该把两个按钮放在右边。但是按钮将占用与表格相同的空间,这可能不是您想要的,因此您可能需要为表格提供垂直尺寸提示。

于 2012-05-22T21:33:01.630 回答