SWT – TabFolder Example
Written on January 7, 2009 at 2:48 am by
mkyong
What is TabFolder?
In SWT, TabFolder is a subclass of a Composite class. The TabFolder can include composite object into a single container through a tabbed index.
How to create a TabFolder?
Here i create a TabFolder composite, add a sashForm composite into a tab 1 and Group composite into a tab 2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Text; public class SWTTabFolder { public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell(display); shell.setText("SWT TabFolder Example"); shell.setLayout(new FillLayout()); TabFolder folder = new TabFolder(shell, SWT.NONE); //Tab 1 TabItem tab1 = new TabItem(folder, SWT.NONE); tab1.setText("Tab 1"); // Create the SashForm with HORIZONTAL SashForm sashForm = new SashForm(folder, SWT.HORIZONTAL); new Button(sashForm, SWT.PUSH).setText("Left"); new Button(sashForm, SWT.PUSH).setText("Right"); tab1.setControl(sashForm); //Tab 2 TabItem tab2 = new TabItem(folder, SWT.NONE); tab2.setText("Tab 2"); Group group = new Group(folder, SWT.NONE); group.setText("Group in Tab 2"); Label label = new Label(group, SWT.BORDER); label.setText("Label in Tab 2"); label.setBounds(10, 100, 100, 100); Text text = new Text(group, SWT.NONE); text.setText("Text in Tab 2"); text.setBounds(10, 200, 100, 100); tab2.setControl(group); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } } |


This article was posted in SWT category.
Oracle Magazine - Free Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for Java's developers and DBAs, and more.
Securing & Optimizing Linux: The Hacking Solution - Free Guide
A comprehensive collection of Linux security products and explanations in the most simple and structured manner on how to safely and easily configure and run many popular Linux-based applications and services.
The Windows 7 Guide: From Newbies to Pros - Free Guide
In this 46 page guide you will be introduced to Windows 7 and what it has to offer. This guide will go over the software compatible issues, you will learn about the new taskbar, how to use and customize Windows Aero, what Windows 7 Libraries are all about, what software is included in Windows 7, and how easy networking is with Windows 7 along with other topics.
All Java Tutorials
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery