Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Freeze first row on table
Freeze first row on table [message #551505] Fri, 06 August 2010 17:58 Go to next message
Sachin Gupta is currently offline Sachin GuptaFriend
Messages: 3
Registered: August 2010
Junior Member
i have table having some editors on first row...when i goes down using down arrow it remains visible..but when i scrolls it using scroll bar it goes there any way using which i can freeze first row of the table.
Re: Freeze first row on table [message #552277 is a reply to message #551505] Wed, 11 August 2010 14:53 Go to previous message
Lakshmi ShanmugamFriend
Messages: 276
Registered: July 2009
Location: India
Senior Member

There is an example on SWT snippets page which fixes first column using two tables. ppets/src/org/eclipse/swt/snippets/

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;
	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
	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);
	// 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 = new TableColumn(bottomTable, SWT.NONE);
	// 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); ();
	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.


Lakshmi P Shanmugam

[Updated on: Wed, 11 August 2010 14:53]

Report message to a moderator

Previous Topic:[UI forms] getting reference to a Form's TitleLabel
Next Topic:Combo with vertical scroll doesn't work
Goto Forum:

Current Time: Mon Dec 09 17:47:38 GMT 2019

Powered by FUDForum. Page generated in 0.01546 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top