Java Reference
In-Depth Information
The
JMenuBar
class defines a
menu bar
usually found at the top of an application window. A
JMenu
ob-
ject represents a top-level menu item on a menu bar that drops down a list of menu items when it is clicked.
The items in a menu are defined by the
JMenuItem
class. The
JPopupMenu
class defines a context menu that
is typically implemented to appear at the current cursor position when the right mouse button is clicked. A
JCheckBoxMenuItem
component is a menu item with a checkbox that is ticked when the item is selected.
The
JRadioButtonMenuItem
class defines a menu item that is part of a group where only one item can be
selected at any time. The group is created by adding
JRadioButtonMenuItem
objects to a
ButtonGroup
ob-
ject. You implement a menu in an application and an applet later in this chapter.
Text Components
The capability of the Swing text components is very wide indeed. The classes in the
javax.swing
packages
that represent text components are shown in
Figure 17-12
.
Like all Swing components, they have the
JCom-
ponent
class as a base.
The most elementary text component is a
JLabel
object, which displays as a single line of text. A
JLabel
component is passive and does not react to input events so you can't edit it. A
JTextField
component looks
similar to a label in that it displays a single line of text, but in this case it is editable. A
JFormattedTex-
tField
component is a
JTextField
component that can control and format the data that is displayed or
entered. It can supply automatic formatting in many instances so it can automatically display a
Date
object
as a date for example. A
JPasswordField
component allows entry of a password as a single line of input
and prevents the characters in the password from being seen.
The
JTextArea
class defines a component that allows editing of multiline text that is contained within
a given area. A
JTextArea
component does not support scrolling directly, but it's easy to add scrollbars by
placing the
JTextArea
component in a
JScrollPane
container.