Java Reference
In-Depth Information
The
JMenuBar
class defines a
menu bar
usually found at the top of an application window. A
JMenu
object represents a top-level menu item on a menu bar that pops up 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
object. We will be implementing 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.
JComponent
JTextComponent
JEditorPane
JLabel
JTextPane
JTextField
JTextArea
JFormattedTextField
The most elementary text component is a
JLabel
object:
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.
JFormattedTextField
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.
Here it has automatically displayed a
Date
object as a date.