SWT Programming with Eclipse
8.3.4. TabFolder
The TabFolder widget allows users to select a page from a set of pages. Although it is a composite, it is not allowed to add composite widgets. A widget that is to be added to a TabFolder must of the TabItem type. The content of a tab can be set by using the TabItem's setControl(Control control) method.
Figure 14. TabFolder widget
A simple TabFolder example is shown below.
Source 11. TabFolder example |
final TabFolder tabFolder = new TabFolder( shell, SWT.BORDER); for (int i=1; i<5; i++) { // create a TabItem TabItem item = new TabItem( tabFolder, SWT.NULL); item.setText( "TabItem " + i); // create a control Label label = new Label( tabFolder, SWT.BORDER); label.setText( "Page " + i); // add a control to the TabItem item.setControl( label ); } |
8.3.5. CoolBar widget
The CoolBar widget provides an area in which you add items on a dynamically positionable space.You can add one or more ToolBar widgets to a CoolBar. A CoolBar can contain one or more CoolItems. Although CoolBar is a composite widget, it is not allowed to add other composite classes. Sub elements of a CoolBar must be of the CoolItem type.
Figure 15. Coolbar widget
The following example shows a CoolBar widget's usage.
Source 12. CoolBar example |
CoolBar coolBar = new CoolBar(shell, SWT.BORDER); coolBar.setLayoutData( new FillLayout()); // create a tool bar which it // the control of the coolItem for (int k = 1; k <3; k++) { ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); for (int i = 1; i < 5; i++) { ToolItem item = new ToolItem(toolBar, SWT.NULL); item.setText("B"+k+"."+i); } // Add a coolItem to a coolBar CoolItem coolItem = new CoolItem(coolBar, SWT.NULL); // set the control of the coolItem coolItem.setControl(toolBar); // You have to specify the size Point size = toolBar.computeSize( SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize (size.x, size.y); coolItem.setSize(coolSize); } |
8.4. A summary of controls having items
Some controls accept sub components as items. For example, a Composite component accepts composite components. Some components need only items. Such components are listed in Table 10.
Table 10. Components having items | ||
Widget | Item | Description |
CoolBar | CoolItem | Items are selectable, dynamically positionable areas of a CoolBar |
Menu | MenuItem | Items are selections under a menu |
TabFolder | TabItem | Items are Tabs in a TabFolder |
Table | TableItem TableColumn |
Items are Rows in a table |
ToolBar | ToolItem | Items are Buttons on the tool bar |
Tree | TreeItem | Items are nodes in a tree |
Conclusion
SWT is the core of the Eclipse user interface. The Eclipse platform is based on the SWT library. To extend your SWT knowledge, you can download SWT examples from the SWT Web site.
About the Author | |
![]() |
|
Resources
Links
- A First Look at Eclipse Plug-In Programming, by Koray Guclu.
- Eclipse uses the Common Public License: http://www.eclipse.org/legal/cpl-v10.html
- Eclipse download site: http://www.eclipse.org/downloads/
- Articles published on the Eclipse Web site: http://www.eclipse.org/arcticles/
- Java download Web site: http://java.sun.com/downloads/index.html
- Eclipse user interface guidelines: http://www.eclipse.org/articles/Article-UI-Guidelines/Index.html
- Quality Eclipse: http://www.qualityeclipse.org/
- SWT Standard Widget Toolkit: http://www.eclipse.org/articles/Article-SWT-Design-1/SWT-Design-1.html
Books
- Eric Clayberg, Dan Rubel, 2004. Eclipse: Building Commercial-Quality Plug-Ins, Pearson Education; June 25, 2004.
- David Gallardo, Ed Burnett, Robert McGovern, 2003. Eclipse in Action: A Guide for Java Developers, Manning Publications.
- Sherry Shavor, Jim D'Anjou, Scott Fairbrother (2003) The Java Developer's Guide to Eclipse, Addison-Wesley Professional.
Page 6 of 6
This article was originally published on March 25, 2004