Create TabFolder and add TabItem : TabFolder « SWT « Java Tutorial

  1. SWT divides its tab implementation into two classes: TabFolder and TabItem.
  2. TabFolders, which aren't visible, contain TabItems.
  3. To create a tabbed interface, create a TabFolder with a Shell as its parent, and create TabItems as children of the TabFolder.
Create TabFolder and add TabItem
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class TabFolderTabItem {

  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 6; i++) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText("TabItem " + i);
      Button button = new Button(tabFolder, SWT.PUSH);
      button.setText("Page " + i);
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())

17.71.1.Create TabFolder and add TabItemCreate TabFolder and add TabItem
17.71.2.Add an event listener to write the selected tab to stdoutAdd an event listener to write the selected tab to stdout
17.71.3.Set selected tabSet selected tab