|
Re: Freeze first row on table [message #552277 is a reply to message #551505] |
Wed, 11 August 2010 14:53 |
|
Lakshmi P Shanmugam Messages: 279 Registered: July 2009 Location: India |
Senior Member |
|
|
Hi,
There is an example on SWT snippets page which fixes first column using two tables. http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co
I have tried to fix the first column using a similar approach using two tables. Here is the modified version of the snippet. You can modify it to suit your requirement.
public class FixedRowTable {
public static void main (String [] args) {
int rowCount = 40;
int columnCount = 3;
final Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
Composite parent = new Composite(shell, SWT.BORDER);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = 0;
parent.setLayout(layout);
final Table topTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION|SWT.NO_SCROLL);
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
gridData.heightHint = SWT.DEFAULT; // use this field to adjust the size of top table
topTable.setLayoutData(gridData);
topTable.setHeaderVisible(true);
topTable.setLinesVisible(true);
final Table bottomTable = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION|SWT.HIDE_SELECTION);
GridData table2Data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
bottomTable.setLayoutData(table2Data);
bottomTable.setLinesVisible(true);
parent.setBackground(topTable.getBackground());
// Create columns for top and bottom tables
for (int i = 0; i < columnCount; i++) {
TableColumn column = new TableColumn(topTable, SWT.NONE);
column.setText("Value "+i);
column.setWidth(100);
column.setResizable(false);
column.setMoveable(false);
column = new TableColumn(bottomTable, SWT.NONE);
column.setWidth(100);
}
// Create rows for top and bottom tables
TableItem item = new TableItem(topTable, SWT.NONE);
for (int j = 0; j < columnCount; j++) {
item.setText(j, "Fixed value @ "+j);
}
for (int i = 0; i < rowCount -1 ; i++) {
item = new TableItem(bottomTable, SWT.NONE);
for (int j = 0; j < columnCount; j++) {
item.setText(j, "Item "+i+" value @ "+j);
}
}
shell.setSize(600, 400);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
If you want the table columns to be movable/resizable, you can add control listener to the the column in the toptable to sync the top and bottom tables.
But, I think you cannot use this approach if you want the columns to support sorting.
HTH,
Lakshmi P Shanmugam
[Updated on: Wed, 11 August 2010 14:53] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02925 seconds