Skip to content

Instantly share code, notes, and snippets.

@wudong
Created February 5, 2013 12:25
Show Gist options
  • Save wudong/4714154 to your computer and use it in GitHub Desktop.
Save wudong/4714154 to your computer and use it in GitHub Desktop.
Use TableColumnLayout to automatically change the table column width when resizing.
// 1
Composite comp = new Composite(shell, SWT.NONE);
Table table = new Table(comp, SWT.BORDER SWT.V_SCROLL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
// 2
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Column 1");
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Column 2");
// 3
TableColumnLayout layout = new TableColumnLayout();
comp.setLayout( layout );
// 4
layout.setColumnData( column1, new ColumnWeightData( 30 ) );
layout.setColumnData( column2, new ColumnWeightData( 60 ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment