I’m attempting to design a SWT UI as a total newbie to both SWT and UI programming in general. Based on the snippets in the SWT documentation I’ve written the following:
Display.setAppName("App Name");
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Group group = new Group(shell, SWT.DEFAULT);
group.setLayout(new GridLayout());
for (int i = 0; i < 3; i++)
new Button(group, SWT.PUSH).setText("ABC" + i);
new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
for (int i = 0; i < 3; i++)
new Button(group, SWT.PUSH).setText("ABC" + i);
new Label(group, SWT.SEPARATOR | SWT.HORIZONTAL);
Table table = new Table(group, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data);
for (String title : new String[] { "A", "B", "C", "D", "E", "F", "G" })
new TableColumn(table, SWT.NONE).setText(title);
for (int i = 0; i < 128; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText(0, "123");
item.setText(1, "234");
item.setText(2, "345");
item.setText(3, "456");
item.setText(4, "567");
item.setText(5, "678");
item.setText(6, "789");
}
for (TableColumn column : table.getColumns())
column.pack();
shell.pack();
shell.open();
while (shell.isDisposed() != true)
if (display.readAndDispatch() != true)
display.sleep();
display.dispose();
}
This results in something like:
ABC1 ABC2 ABC3 | ABC1 ABC2 ABC3 --- Table
If I change the layout on the group to RowLayout() but don’t change the table’s GridData() to RowData() I get a class cast exception. If I change it to RowData() I get something that looks like:
ABC1 ABC2 ABC3 | ABC1 ABC2 ABC3 ---- Table
What I want is this:
ABC1 ABC2 ABC3 | ABC1 ABC2 ABC3
-------------------------------
Table
Any suggestions?
Set the shell layout to gridLayout with a width of 2. Then when you make your table, set the gridData horizontal span to 2
Mostly from memory, untested
This should set up your GridLayout to have two columns, so you add g1 and it goes top left, g1 and it goes top right. Then you specify that t1 is going to take up two columns, so when you add it it takes the whole second row. It’s also ignoring your separator label for now.