following code gives me a construct like in the picture-link below. For instance I have one main group with 3 groups inside. Every group has a table with 3 columns and a minimum width of 200. If you resize the composite, the tables and groups resizes as well. But if the size is smaller than 200, there appears a scrollbar under every single table. In fact my intention was to see ONE scrollbar under the tables. I've tried also a ScrolledComposite-"Layer" between maingroup and the smaller groups, but it didnt work. Can someone give me an example how can i create one scrollbar instead of 3?
Thanks!
picture: http://www.bilder-upload.eu/show.php?file=d94e50-1432047327.jpg
public class GroupTable
{
private static Composite composite;
private static ArrayList<Table> tablesList = new ArrayList<Table>();
private static int minWidth = 100;
public static void main(String[] args)
{
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
composite = new Composite(shell, SWT.BORDER);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = 0;
composite.setLayout(layout);
// MainGroup
Group gr = new Group(composite, SWT.NONE);
GridLayout gLayout = new GridLayout(3, false);
gr.setLayout(gLayout);
GridData griddata = new GridData(SWT.FILL, SWT.FILL, true, false);
gr.setLayoutData(griddata);
gr.setText("Main Group");
for (int i = 0; i < 3; i++)
{
createGroups(gr, layout, i);
}
composite.addControlListener(new ControlAdapter()
{
@Override
public void controlResized(ControlEvent e)
{
for (Table table : tablesList)
{
Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
ScrollBar vBar = table.getVerticalBar();
Composite group = table.getParent();
Rectangle area = group.getClientArea();
Rectangle t1 = area;
Rectangle t2 = table.computeTrim(0, 0, 0, 0);
Point t3 = vBar.getSize();
int width = t1.width - t2.width - t3.x;
if (size.y > area.height + table.getHeaderHeight())
{
// Subtract the scrollbar width from the total column
// width if a vertical scrollbar will be required
Point vBarSize = vBar.getSize();
width -= vBarSize.x;
}
TableColumn[] columnse = table.getColumns();
int colCount = columnse.length;
Point oldSize = table.getSize();
if (oldSize.x > area.width)
{
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
for (TableColumn column : columnse)
{
if (width / colCount < minWidth)
{
width = minWidth * colCount;
}
column.setWidth(width / 3);
}
table.setSize(area.width, area.height);
}
else
{
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
table.setSize(area.width, area.height);
for (TableColumn column : columnse)
{
if (width / colCount < minWidth)
{
width = minWidth * colCount;
}
column.setWidth(width / 3);
}
}
}
}
});
shell.setSize(900, 400);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void createGroups(Composite parentGroup, GridLayout layout, int i)
{
Group group = new Group(parentGroup, SWT.NONE);
group.setLayout(layout);
GridData griddata1 = new GridData(SWT.FILL, SWT.FILL, true, true);
group.setLayoutData(griddata1);
group.setText("group " + i);
createTables(group, i);
}
private static void createTables(Group parent, int tn)
{
Table table = new Table(parent, SWT.FULL_SELECTION);
tablesList.add(table);
TableViewer localTableViewer = new TableViewer(table);
localTableViewer.getControl().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
for (int j = 0; j < 3; j++)
{
TableViewerColumn column = new TableViewerColumn(localTableViewer,
SWT.NONE);
column.getColumn().setText("column " + j);
column.getColumn().pack();
}
for (int i = 0; i < 10; i++)
{
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[]{"i ", "am", "table " + tn});
}
table.setHeaderVisible(true);
}
}