Reputation: 567
I'm making a custom dialog with JFace but having trouble with my columns not displaying. Here's my code. All I get is the table with no columns and a blue line to the left. This extends JFace dialog.
@Override
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout());
addTableToDialog(container);
container.getShell().setSize(600, 400);
return container;
}
private void addTableToDialog(Composite container)
{
_tableViewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
_tableViewer.getTable().setHeaderVisible(true);
_tableViewer.getTable().setLinesVisible(true);
_tableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
renderHeaders();
}
private void renderHeaders() {
int bound = 1;
for (int header = 0; header < _headers.length; header++)
{
String tableHeader = _headers[header];
createTableViewerColumn(tableHeader, bound);
}
}
private TableViewerColumn createTableViewerColumn(String title, int bound)
{
final TableViewerColumn viewerColumn = new TableViewerColumn(_tableViewer, SWT.NONE);
final TableColumn tableColumn = viewerColumn.getColumn();
tableColumn.setText(title);
tableColumn.setResizable(true);
tableColumn.setMoveable(true);
_tableColumnLayout.setColumnData(tableColumn, new ColumnWeightData(bound));
return viewerColumn;
}
Upvotes: 2
Views: 308
Reputation: 567
The following solved this problem for me. I define the TableColumnLayout when I'm creating the TableViewer and set this as the layout for a composite that contains the table.
private void addTableToDialog(Composite container)
{
TableColumnLayout tableColumnLayout = new TableColumnLayout();
Composite tableContainer = new Composite(container, SWT.NONE);
tableContainer.setLayout(tableColumnLayout);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
_tableViewer = new TableViewer(tableContainer, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
_tableViewer.getTable().setHeaderVisible(true);
_tableViewer.getTable().setLinesVisible(true);
renderHeaders(tableColumnLayout);
}
Upvotes: 1