February 25, 2021
Hot Topics:

SWT Programming with Eclipse

  • By Koray Guclu
  • Send Email »
  • More Articles »
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
Items are Rows in a table
ToolBar ToolItem Items are Buttons on the tool bar
Tree TreeItem Items are nodes in a tree


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

Koray Güclü

He is working as a freelance author and software architect. He is currently finishing his book on Software Architectures and Design Patterns. His main interest areas are Software Architectures, Data Warehouses, and Database Modeling.





Page 6 of 6

This article was originally published on March 25, 2004

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date