有人可以帮我吗? 我在 SWT 中有一个表格,我只是想显示一些表格项目,但该表格仅显示一个项目,其他项目具有垂直滚动。我想展示一切,而不滚动。我尝试使用选项 SWT_NO_SCROLL 但不起作用。我有一个创建表格和其他填充它的方法,创建一个新的表格项目,它们运行良好,问题是只显示第一个项目,其他项目正在滚动。
我的代码是:
private void createTable(Composite parent){
table = new Table (parent, SWT.BORDER);
TableColumn tcFile = new TableColumn(table, SWT.LEFT);
TableColumn tcStatus = new TableColumn(table, SWT.LEFT);
tcFile.setText("File");
tcStatus.setText("Status");
tcFile.setWidth(500);
tcStatus.setWidth(500);
table.setVisible(true);
table.setHeaderVisible(true);
}
private void populateTable(String file, String status){
TableItem item = new TableItem(table, SWT.LEFT);
item.setText(new String[] { file, status});
}
Composite top = new Composite(parent, SWT.WRAP);
GridLayout layout = new GridLayout();
layout.marginHeight = -5;
layout.marginWidth = 0;
top.setLayout(layout);
Composite banner = new Composite(top, SWT.WRAP);
banner.setLayoutData(new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_BEGINNING, false, false));
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 10;
layout.numColumns = 5;
banner.setLayout(layout);
createTable(top);
最佳答案
您尚未为Table
指定任何布局数据,请尝试以下操作:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data);
如果您没有其他任何东西来设置对话框/窗口大小,您可能需要指定表格高度提示:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200; // Vertical size for table
table.setLayoutData(data);
关于java - SWT - 显示多个表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30833576/