Java Reference
In-Depth Information
TabbedPane();
TabbedPane(
int
tabPosition);
add(Component comp);
add(String tabText, Component comp);
add(Component comp,
int
index);
setTitleAt(
int
pos, String tabTitle);
setSelectedComponent(Component comp);
setSelectedIndex(
int
pos)
TabbedPane()
- constructor. The tabs are placed on the upper edge.
TabbedPane(int tabPosition)
- constructor in which one can specify the posi-
tion of the tabs. The four values for parameter
tabPosition
are predefined in
class
JTabbedPane
:
TOP
,
BOTTOM
,
LEFT
,
RIGHT
.
add(Component comp)
adds
comp
as last page. 'Last' means that the tab is the
right-most (or bottom-most) one. The tab does not have any text.
add(String tabText, Component comp)
adds
comp
as last page. 'Last' means that
the tab is the right-most (or bottom-most) one. The tab is labelled by
tabTitle
.
add(Component comp, int index)
adds
comp
such that the corresponding tab is
at position
index
. The tab does not have any text.
setTitleAt(int pos, String tabTitle)
assigns a new text
tabTitle
to the tab
at position
pos
.
setSelectedComponent(Component comp)
selects the page containing compo-
nent
comp
, i.e. this page is made visible.
setSelectedIndex(int pos)
selects the page whose tab is at position
pos
, i.e.
this page is made visible.
The listing
TabbedPaneFrame
below shows how to use a tabbed pane. As we do not
add any new functions we use a
JTabbedPane
and do not extend it into a new class.
The tabbed pane is glued into a frame. Then four components are added to to the
tabbed pane. At first we add two
JLabel
s, each displaying an image. Then we add
red
ColorPanel
. This is defined in the package
its.SimpleFrameWithPanels
.
Finally we add a
JTextArea
which contains some text describing what the four
components are. The
JTextArea
is added at position 0 so that its tab is the
left-most. We then set the selected index to 1 which makes the image of the plum
visible. The result is shown in Figure 16.10.
File:
its/TabbedPane/TabbedPaneFrame.java
1.
package
its.TabbedPane;
2.
3.
import
its.SimpleFrame.SimpleFrame;
4.
import
its.SimpleFrameWithPanels.ColorPanel;
Search WWH ::
Custom Search