Java Reference
In-Depth Information
Message dialog type
Icon
Description
Indicates an error.
ERROR_MESSAGE
Indicates an informational message.
INFORMATION_MESSAGE
WARNING_MESSAGE
Warns of a potential problem.
Poses a question. This dialog normally requires a
response, such as clicking a Yes or a No button.
QUESTION_MESSAGE
PLAIN_MESSAGE
no
icon
A dialog that contains a message, but no icon.
Fig. 12.3 | JOptionPane static constants for message dialogs.
12.4 Overview of Swing Components
Though it's possible to perform input and output using the JOptionPane dialogs, most
GUI applications require more elaborate user interfaces. The remainder of this chapter
discusses many GUI components that enable application developers to create robust
GUIs. Figure 12.4 lists several basic Swing GUI components that we discuss.
Component
Description
JLabel
Displays uneditable text and/or icons.
JTextField
Typically receives input from the user.
JButton
Triggers an event when clicked with the mouse.
JCheckBox
Specifies an option that can be selected or not selected .
JComboBox
A drop-down list of items from which the user can make a selection .
JList
A list of items from which the user can make a selection by clicking on any one
of them. Multiple elements can be selected.
JPanel
An area in which components can be placed and organized .
Fig. 12.4 | Some basic Swing GUI components.
Swing vs. AWT
There are actually two sets of Java GUI components. In Java's early days, GUIs were built
with components from the Abstract Window Toolkit ( AWT ) in package java.awt .
These look like the native GUI components of the platform on which a Java program ex-
ecutes. For example, a Button object displayed in a Java program running on Microsoft
Windows looks like those in other Windows applications. On Apple Mac OS X, the But-
ton looks like those in other Mac applications. Sometimes, even the manner in which a
user can interact with an AWT component differs between platforms . The component's ap-
pearance and the way in which the user interacts with it are known as its look-and-feel .
 
 
Search WWH ::




Custom Search