【发布时间】:2014-12-18 16:25:17
【问题描述】:
我想创建一个包含两个表格的对话框。这两个表必须共享垂直对齐的空间。如果表格中有许多元素,则必须出现滚动条。
@Override
protected Control createDialogArea(Composite parent) {
createSecondDialog();
GridLayoutFactory layout = GridLayoutFactory.fillDefaults().numColumns(
1);
GridDataFactory grid = GridDataFactory.fillDefaults().grab(true, false);
Composite composite = (Composite) super.createDialogArea(parent);
layout.applyTo(composite);
composite.setBackground(Display.getDefault().getSystemColor(
SWT.COLOR_CYAN));
Composite section = new Composite(composite, SWT.NONE);
layout.applyTo(section);
grid.applyTo(section);
createTable(section);
createTable(section);
return composite;
}
private TableViewer createTable(Composite area) {
CheckboxTableViewer table = CheckboxTableViewer.newCheckList(area,
SWT.READ_ONLY | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL);
table.getTable().setBackground(
Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
GridDataFactory.fillDefaults().grab(true, false).
.applyTo(table.getTable());
table.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof String) {
return (String) element;
}
return "Test";
}
});
table.setContentProvider(ArrayContentProvider.getInstance());
Collection<String> input = new ArrayList<String>();
fillArrayList(input);
table.setInput(input);
table.getTable().setHeaderVisible(true);
table.getTable().setLinesVisible(true);
Button copyButton = new Button(area, SWT.PUSH);
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL)
.applyTo(copyButton);
copyButton.setText("Instant Copy");
copyButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent selectionevent) {
// TODO Auto-generated method stub
}
});
return table;
}
我正在苦苦挣扎,不知道实现我的要求的答案。
感谢您的帮助!
【问题讨论】:
-
你的代码,到底是什么样子的?它与您尝试实现的目标有何不同?
-
桌子的高度不受限制。如果我每张桌子有 500 个项目,我就没有滚动条。桌子走出窗外。我的愿望是获得一个对话框,假设高度为 550 像素,在此窗口中 2 个高度为 250 像素的表格,如果表格中的项目超过表格可以显示的表格,则表格必须获得滚动条。
标签: java swt grid-layout