10.1. Creating SWT Tab Folders
Problem
Space is at a premium in your application, and you want to divide your widgets into a set of pages.
Solution
Try a tab folder widget, which enables you to stack pages of widgets.
Create a new TabFolder object, add
TabItem objects to it, and use the
TabItem objects as widget containers.
Discussion
Tab folders are not difficult to create and stack with widgets. Just
create an object of the TabFolder class, as in the
TabApp example in the code for the book.
Here’s a selection of the most popular
TabFolder methods:
-
void addSelectionListener(SelectionListener listener) Adds the listener to the collection of listeners who will be notified when the tab folder’s selection changes
-
TabItem getItem(int index) Returns the item at the given zero-relative index in the tab folder
-
int getItemCount( ) Returns the number of items in the tab folder
-
TabItem[] getItems( ) Returns an array of
TabItemobjects that are the items in the tab folder-
void setSelection(int index) Selects the item at the given zero-relative index in the tab folder
Here’s how the TabApp
application creates a tab folder:
final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
.
.
.After creating a tab folder, add as many TabItem
objects as you need to create the pages in the tab folder.
Here’s a selection of the most useful
TabItem methods:
-
TabFolder getParent( ) Returns the tab item’s parent, which must be a
TabFolderobject-
void setControl(Control control) Sets the control that is used ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access