Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-2008, 10:04 AM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default SWT GridLayout
The code snippet below uses grid layout and adds buttons to it. It is a a good example for the beginners:
Code:
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		final Composite c = new Composite(shell, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 3;
		c.setLayout(layout);
		for (int i = 0; i < 10; i++) {
			Button b = new Button(c, SWT.PUSH);
			b.setText("Button " + i);
		}
 
		Button b = new Button(shell, SWT.PUSH);
		b.setText("add a new button at row 2 column 1");
		final int[] index = new int[1];
		b.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				Button s = new Button(c, SWT.PUSH);
				s.setText("Special " + index[0]);
				index[0]++;
				Control[] children = c.getChildren();
				s.moveAbove(children[3]);
				shell.layout(new Control[] { s });
			}
		});
 
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridLayout with animation? tojas AWT / Swing 3 11-12-2007 11:16 PM
Use GridLayout in java toby Java Applets 1 08-04-2007 01:44 AM
Help with gaps in GridLayout trill AWT / Swing 1 07-31-2007 08:20 PM
Gridlayout Marty AWT / Swing 2 05-31-2007 12:48 PM


All times are GMT +2. The time now is 09:05 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org