Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Simple SWT Table(Header size, center a cell)
Simple SWT Table [message #633050] Fri, 15 October 2010 08:25 Go to next message
Andrea  is currently offline Andrea Friend
Messages: 7
Registered: October 2010
Junior Member
Hi,
I'm a new user of SWT. I have a problem:
I have edited a simple snippets file

package swtsnippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class ParkedTable {
	static Image image;
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		Table table = new Table(shell, SWT.MULTI | SWT.BORDER
				| SWT.FULL_SELECTION);
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
		data.heightHint = 200;
		table.setLayoutData(data);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		
		image = new Image(display, "C:\\antenna.png");
		createColumns(table);

		setData(table);
		
		resizeColumns(table);
	    
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}

	private static void resizeColumns(Table table) {
		for (int i=1; i<4; i++) {
			table.getColumn (i).pack ();
			table.getColumn(2).setAlignment(SWT.CENTER);
			System.out.println(table.getHeaderHeight()); 
		}
		
	}

	private static void setData(Table table) {
		for (int i=0; i<12; i++) {
			TableItem item = new TableItem (table, SWT.NONE);
			item.setText (0, "0x0000");
			item.setText (1, "0x466467-0x466ef7");
			
			Button b = new Button(table, SWT.CHECK | SWT.CENTER);
			
			TableEditor editor = new TableEditor (table);
			editor.grabHorizontal = editor.grabVertical = true;
			editor.setEditor (b, item, 2);
			
			b = new Button(table, SWT.CHECK | SWT.RESIZE);
			
			
			editor = new TableEditor (table);
			editor.grabHorizontal = editor.grabVertical = true;
			editor.setEditor (b, item, 3);
		}
		
	}

	private static void createColumns(Table table) {
		// Create five columns
	      TableColumn column = new TableColumn(table, SWT.CENTER);
	      column.setImage(image);
	      column.setWidth(50);
	      
	      column = new TableColumn(table, SWT.CENTER);
	      column.setText("MAC Address");
	      
	      column = new TableColumn(table, SWT.CENTER);
	      column.setText("Parked");
	      
	      column = new TableColumn(table, SWT.CENTER);
	      column.setText("Active");
	}
}


There are tree problems:
I want set the header size from 24 to 30 px
I want center checkbox button in cells...
I want change background color of some cells

Thanks.
Andrea

[Updated on: Fri, 15 October 2010 09:17]

Report message to a moderator

Re: Simple SWT Table [message #633497 is a reply to message #633050] Mon, 18 October 2010 08:45 Go to previous messageGo to next message
Andrea  is currently offline Andrea Friend
Messages: 7
Registered: October 2010
Junior Member
If i'm not been clear... reply me..
Re: Simple SWT Table [message #633561 is a reply to message #633050] Mon, 18 October 2010 12:21 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
Hi,

1) There is no method currently to set the header size.
2) You can place the buttons in the center of the cell using
editor.horizontalAlignment = SWT.CENTER; and editor.grabHorizontal = false. Also set editor.minimumWidth.
Please see this snippet for an example --> Snippet126
3) You can the change the background of the table cells using Custom drawing. Please see Snippet229. Also helpful --> Article on custom drawing


Lakshmi P Shanmugam
Re: Simple SWT Table [message #633602 is a reply to message #633561] Mon, 18 October 2010 14:24 Go to previous message
Andrea  is currently offline Andrea Friend
Messages: 7
Registered: October 2010
Junior Member
Ok thanks a lot. Very usefull response
Previous Topic:Table with scrollbar
Next Topic:SWT Browser Scrollbar
Goto Forum:
  


Current Time: Fri Mar 29 11:13:36 GMT 2024

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

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

Back to the top