Java Reference
In-Depth Information
LISTING 10.5
Continued
45: add(“Center”, scroll);
46: setJMenuBar(menubar);
47: pack();
48: setVisible(true);
49: }
50:
51: public static void main(String[] arguments) {
52: FeedBar2 frame = new FeedBar2();
53: }
54: }
Tabbed Panes
Tabbed panes, a group of stacked panels in which only one panel can be viewed at a
time, are implemented in Swing by the JTabbedPane class.
10
To view a panel, you click the tab that contains its name. Tabs can be arranged horizon-
tally across the top or bottom of the component or vertically along the left or right side.
Tabbed panes are created with the following three constructor methods:
JTabbedPane() —Creates a vertical tabbed pane along the top that does not scroll
n
JTabbedPane( int ) —Creates a tabbed pane that does not scroll and has the speci-
fied placement
n
JTabbedPane( int , int ) —Creates a tabbed pane with the specified placement
(first argument) and scrolling policy (second argument)
n
The placement of a tabbed pane is the position where its tabs are displayed in relation to
the panels. Use one of four class variables as the argument to the constructor:
JTabbedPane.TOP , JTabbedPane.BOTTOM , JTabbedPane.LEFT , or JTabbedPane.RIGHT .
The scrolling policy determines how tabs will be displayed when there are more tabs
than the interface can hold. A tabbed pane that does not scroll displays extra tabs on their
own line, which can be set up using the JTabbedPane.WRAP_TAB_LAYOUT class variable.
A tabbed pane that scrolls displays scrolling arrows beside the tabs. This can be set up
with JTabbedPane.SCROLL_TAB_LAYOUT .
After you create a tabbed pane, you can add components to it by calling the pane's
addTab( String , Component ) method. The String argument will be used as the label of
the tab. The second argument is the component that will make up one of the tabs on the
pane. It's common to use a JPanel object for this purpose, but not required.
 
Search WWH ::




Custom Search