Java Reference
In-Depth Information
/** This JTabbedPane subclass holds three panes,
* each with one button.
**/
class Tabs extends JTabbedPane
implements ActionListener
{
JApplet fApplet;
/** Put a button on each of three pages. **/
Tabs (JApplet applet) {
fApplet = applet;
add (makeButton ("1"), "One");
add (makeButton ("2"), "Two");
add (makeButton ("3"), "Three");
} // ctor
/** Make a button here and add this object
*toits action listeners list.
**/
JButton makeButton (String name) {
JButton b = new JButton (name);
b.addActionListener (this);
return b;
}
/** When button pushed, show message on the
* browser status bar.
**/
public void actionPerformed (ActionEvent e) {
JButton but = (JButton) (e.getSource ());
String str = but.getText ();
fApplet.showStatus ("Pushed button "+ str);
}
} // class Tabs
The JTabbedPane class provides the add() method for adding a component
along with a label that goes on the page tab. You can also add icons and mnemonics
for the tabbed labels as well. ( Mnemonics allow you to select a page with key
combination such as “ Alt-a ”.)
7.4.5 SpringLayout
The layout manager javax.swing.SpringLayout came with Java 1.4 and
works by placing constraints on the distances between edges of components. The
 
Search WWH ::




Custom Search