Resize Table in a (Scrolled)Composite [message #462100] |
Thu, 06 October 2005 11:50 |
martin Messages: 49 Registered: July 2009 |
Member |
|
|
I'd like to see the table in a ScrolledComposite automatically resized to
the full width and height of this composite whenever the user resizes the
application window. How can I do that?
For example:
-----------------------------8<------------------------------
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.*;
public class TableResizeProblem {
public static void main (String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new GridLayout());
new Label(shell, SWT.NONE).setText("Kilometer: ");
Text kilometer = new Text(shell, SWT.SINGLE | SWT.BORDER);
kilometer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final ScrolledComposite sc1 = new ScrolledComposite(shell,
SWT.V_SCROLL | SWT.BORDER);
Table tableWater = new Table(sc1, SWT.NONE);
tableWater.setHeaderVisible(true);
tableWater.setLinesVisible(true);
TableColumn columnWater = new TableColumn(tableWater, SWT.NONE);
columnWater.setText("Water");
TableColumn columnKst = new TableColumn(tableWater, SWT.NONE);
columnKst.setText("Kst-Value");
TableColumn columnKstBl = new TableColumn(tableWater, SWT.NONE);
columnKstBl.setText("Kst-Block");
for(int i = 0; i < 27; ++i) {
TableItem item = new TableItem(tableWater, SWT.NULL);
for(int j = 0; j < 3; ++j) {
item.setText(j, "Item " + i + "-" + j);
}
}
for(int i = 0; i < 3; ++i) {
TableColumn column = tableWater.getColumn(i);
column.pack();
}
tableWater.pack();
sc1.setContent(tableWater);
GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1,
1);
gridData1.heightHint = 400;
sc1.setLayoutData(gridData1);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
-----------------------------8<------------------------------
Besides that: Why do I need the tableWater.pack() to see the table in the
composite? Is there another way to do that?
Martin
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03547 seconds