Java Reference
In-Depth Information
Swing Components
Although the Java 2 platform still supports the AWT components,
it is recommended that you use Swing components instead
because they contain more methods to manipulate and
implement basic GUI-related features.
Table 7-3 lists some of the advantages of using Swing components.
Table 7-3 Swing Component Advantages
ADVANTAGES OF USING SWING COMPONENTS
1. Swing Buttons and Labels can display images instead of, or in addition to, text.
2. Borders may be drawn around most Swing components.
3. Swing components do not have to be rectangular. JButtons, for example, can be round.
4. Assistive technologies can obtain information from Swing components. For example, a screen reader easily
can read the text that is displayed on a JButton or JLabel.
5. Swing components allow programmers and developers to specify the look and feel of the GUI. By contrast,
AWT components always have the look and feel of the native platform.
6. Some Swing components use external objects to hold information about the state of the component. The
Swing slider bar, JSlider, for example, automatically is associated with a BoundedRangeModel object to hold
its current value and range of legal values.
Most of the AWT components have a counterpart in the Swing package. The
AWT button class, for example, is named Button, while the Swing button class is
named JButton. The AWT container, Frame, has a JFrame version that provides
the same functionality but with more features. Table 7-4 displays a comparison
list of AWT and Swing components.
Table 7-4 Swing Components versus AWT Components
SWING COMPONENTS
AWT COMPONENTS
ADVANTAGES OF USING SWING COMPONENTS
JLabel
Label
May use text or image or both
JTextField
TextField
More methods to manipulate text; can be overlaid with a viewport for
additional layering of components
JCheckBox
Checkbox
Uses two different controls with more methods, whereas AWT
JOptionButton
groups a single control
JButton
Button
May have images on the button; button may take different shapes
JComboBox
ComboBox
May take two different forms: editable and uneditable
JTextArea
TextArea
Separates the scrolling capability, size, word wrap, and other
properties to a viewport or JScrollPane for more flexibility
JPanel
Panel
Supports all the Swing methods inherited from containers
JFrame
Frame
Uses a content pane container to provide more flexibility
JApplet
Applet
Supports the JFC/Swing component architecture
JMenuBar
MenuBar
Creates menus as buttons for greater flexibility in creating shortcut
menus and pop-up menus
 
Search WWH ::




Custom Search