Setting a Default Tab

Since the SWT does a good job of hiding the inner workings of the tab folder and tab pages, handling the task of making controls visible and invisible as the user navigates the tabs, you won’t frequently use many methods on TabFolder. The ones that are useful deal with determining which tab page is selected. As you might guess, there are methods that enable you to force a tab page to the front without the user having clicked the tab, while other methods that enable you to determine which page currently has the focus.

How do I do that?

To force a tab to the front, add the following:

Note

To set a default, just force a tab to the front when the window is first displayed.

tf.setSelection(1);

This results in the second tab (tabs are zero-indexed) coming to the front.

To determine which tab is currently selected:

tf.getSelectionIndex( );

Tabs are a wonderful way to spruce up your user interface. Most applications today make liberal use of this construct. Fortunately, SWT makes creating tabbed folders a snap.

Get SWT: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.