JTabbedPane class for displaying and manipulating : TabbedPane « Swing JFC « Java






JTabbedPane class for displaying and manipulating

JTabbedPane class for displaying and manipulating
 
/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly 
*/
// SysConfig.java
//A demonstration of the JTabbedPane class for displaying and manipulating
//configuration information. The BoxLayout class is used to layout the
//first tab quickly.
//

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

public class SysConfig extends JFrame {
  JTabbedPane config = new JTabbedPane();

  public SysConfig() {
    super("JTabbedPane & BoxLayout Demonstration");
    setSize(500, 300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel configPane = new JPanel();
    configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS));
    JTextArea question = new JTextArea("Which of the following options\n"
        + "do you have installed?");
    // Ok, now configure the textarea to show up properly inside the box.
    // This is part of the "high art" of Swing...
    question.setEditable(false);
    question.setMaximumSize(new Dimension(300, 50));
    question.setAlignmentX(0.0f);
    question.setBackground(configPane.getBackground());

    JCheckBox audioCB = new JCheckBox("Sound Card", true);
    JCheckBox nicCB = new JCheckBox("Ethernet Card", true);
    JCheckBox tvCB = new JCheckBox("Video Out", false);

    configPane.add(Box.createVerticalGlue());
    configPane.add(question);
    configPane.add(audioCB);
    configPane.add(nicCB);
    configPane.add(tvCB);
    configPane.add(Box.createVerticalGlue());

    JLabel audioPane = new JLabel("Audio stuff");
    JLabel nicPane = new JLabel("Networking stuff");
    JLabel tvPane = new JLabel("Video stuff");
    JLabel helpPane = new JLabel("Help information");

    audioCB.addItemListener(new TabManager(audioPane));
    nicCB.addItemListener(new TabManager(nicPane));
    tvCB.addItemListener(new TabManager(tvPane));

    config.addTab("System", null, configPane, "Choose Installed Options");
    config.addTab("Audio", null, audioPane, "Audio system configuration");
    config.addTab("Networking", null, nicPane, "Networking configuration");
    config.addTab("Video", null, tvPane, "Video system configuration");
    config.addTab("Help", null, helpPane, "How Do I...");

    getContentPane().add(config, BorderLayout.CENTER);
  }

  class TabManager implements ItemListener {
    Component tab;

    public TabManager(Component tabToManage) {
      tab = tabToManage;
    }

    public void itemStateChanged(ItemEvent ie) {
      int index = config.indexOfComponent(tab);
      if (index != -1) {
        config.setEnabledAt(index,
            ie.getStateChange() == ItemEvent.SELECTED);
      }
      SysConfig.this.repaint();
    }
  }

  public static void main(String args[]) {
    SysConfig sc = new SysConfig();
    sc.setVisible(true);
  }
}

           
         
  








Related examples in the same category

1.Demonstrates the Tabbed PaneDemonstrates the Tabbed Pane
2.A demonstration of the tab wrapping property of JTabbedPaneA demonstration of the tab wrapping property of JTabbedPane
3.A quick test of the JTabbedPane componentA quick test of the JTabbedPane component
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.