Java Reference
In-Depth Information
The following statements create five empty panels and add them to a tabbed pane:
JPanel mainSettings = new JPanel();
JPanel advancedSettings = new JPanel();
JPanel privacySettings = new JPanel();
JPanel emailSettings = new JPanel();
JPanel securitySettings = new JPanel();
JTabbedPane tabs = new JTabbedPane();
tabs.addTab(“Main”, mainSettings);
tabs.addTab(“Advanced”, advancedSettings);
tabs.addTab(“Privacy”, privacySettings);
tabs.addTab(“E-mail”, emailSettings);
tabs.addTab(“Security”, securitySettings);
After adding all the panels and other components to a tabbed pane, the pane can be
added to another container. Figure 10.15 shows what the example looks like when added
to a frame.
FIGURE 10.15
A tabbed pane
with five tabs dis-
played along the
top edge.
Summary
You now know how to paint a user interface onto a Java application window using the
components of the Swing package.
Swing includes classes for many of the buttons, bars, lists, and fields you would expect
to see on a program, along with more advanced components, such as sliders, dialog
boxes, progress bars, and menu bars. Interface components are implemented by creating
an instance of their class and adding it to a container such as a frame using the con-
tainer's add() method or a similar method specific to the container, such as the tabbed
pane's addTab() method.
Today, you developed components and added them to an interface. During the next two
days, you will learn about two things required to make a graphical interface usable: how
to arrange components together to form a whole interface and how to receive input from
a user through these components.
 
Search WWH ::




Custom Search