【发布时间】:2017-08-09 18:55:42
【问题描述】:
您好,我是 java 初学者,我的表格大小有问题。
在first picture上你可以看到尺寸很好,但是当我点击按钮时表格的尺寸会缩小picture two)。
感谢您的帮助:)
protected void createContents() {
...
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(gridData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn columnProduct = new TableColumn(table, SWT.NONE);
columnProduct.setText("Product");
TableColumn columnKey = new TableColumn(table, SWT.NONE);
columnKey.setText("Key");
for (int i = 0; i < 2; i++)
{
table.getColumn(i).pack();
}
shell.pack();
shell.open();
}
@Override
public void mouseDown(MouseEvent e) {
TableItem tItem = new TableItem(table, SWT.FILL);
String[] data = { txtProduct.getText(), txtKey.getText()};
tItem.setText(data);
table.pack();
}
【问题讨论】:
-
table.pack();就是这样做的。您的预期结果是什么? -
我希望列自动调整到右侧(使用可用空间)并且表格自动调整到底部。 Example