Demonstrates the Tabbed Pane : TabbedPane « Swing JFC « Java






Demonstrates the Tabbed Pane

Demonstrates the Tabbed Pane
 

// : c14:TabbedPane1.java
// Demonstrates the Tabbed Pane.
// <applet code=TabbedPane1 width=350 height=200></applet>
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class TabbedPane1 extends JApplet {
  private String[] flavors = { "Chocolate", "Strawberry",
      "Vanilla Fudge Swirl", "Mint Chip", "Mocha Almond Fudge",
      "Rum Raisin", "Praline Cream", "Mud Pie" };

  private JTabbedPane tabs = new JTabbedPane();

  private JTextField txt = new JTextField(20);

  public void init() {
    for (int i = 0; i < flavors.length; i++)
      tabs.addTab(flavors[i], new JButton("Tabbed pane " + i));
    tabs.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        txt.setText("Tab selected: " + tabs.getSelectedIndex());
      }
    });
    Container cp = getContentPane();
    cp.add(BorderLayout.SOUTH, txt);
    cp.add(tabs);
  }

  public static void main(String[] args) {
    run(new TabbedPane1(), 350, 200);
  }

  public static void run(JApplet applet, int width, int height) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(applet);
    frame.setSize(width, height);
    applet.init();
    applet.start();
    frame.setVisible(true);
  }
} ///:~


           
         
  








Related examples in the same category

1.A demonstration of the tab wrapping property of JTabbedPaneA demonstration of the tab wrapping property of JTabbedPane
2.A quick test of the JTabbedPane componentA quick test of the JTabbedPane component
3.JTabbedPane class for displaying and manipulatingJTabbedPane class for displaying and manipulating
4.TabbedPane SampleTabbedPane Sample
5.TabbedPane Sample 2TabbedPane Sample 2
6.TabbedPane DemoTabbedPane Demo
7.Laying Out a Screen with JTabbedPaneLaying Out a Screen with JTabbedPane
8.TabPane DemoTabPane Demo
9.Determining When the Selected Tab Changes in a JTabbedPane Container
10.Enable Scrolling Tabs in a JTabbedPane Container
11.Enabling the Selection of a Tab in a JTabbedPane Container Using a Keystroke
12.Setting the Color of a Tab in a JTabbedPane Container
13.Setting the Tool Tip for a Tab in a JTabbedPane Container
14.Enabling and Disabling a Tab in a JTabbedPane Container
15.Setting the Location of the Tabs in a JTabbedPane Container
16.Getting the Tabs in a JTabbedPane Container
17.Retrieve the index of a tab when needed
18.Get the index of the first tab that matches an icon
19.Get the index of the tab by matching the child component
20.Moving a Tab in a JTabbedPane Container
21.Removing a Tab in a JTabbedPane Container
22.Add a tab with a label taken from the name of the component
23.Add a tab with a label at the end of all tabs
24.Add a tab with a label and icon at the end of all tabs
25.Add a tab with a label, icon, and tool tip at the end of all tabs
26.Insert a tab after the first tab
27.Getting and Setting the Selected Tab in a JTabbedPane Container
28.Creating a JTabbedPane Container
29.Setting the Size of the Divider in a JSplitPane Container
30.This program demonstrates the tabbed pane component organizer.This program demonstrates the tabbed pane component organizer.