![]() ![]() ![]() ![]() |
Converting to Swing |
Use the following table as a guide for choosing a Swing replacement for each AWT component used in your program.
AWT Component Closest Swing Equivalent Notes java.applet.Applet
JApplet
AWT applets and Swing applets differ in several ways. See Converting Applets. Button
JButton
A Swing button can include an image and/or text. Canvas
JPanel
,JLabel
, or another appropriate Swing component
Your choice depends on what the program uses the canvas for. See Converting Canvases for a discussion of your conversion options. Checkbox
JCheckBox
or
JRadioButton
Note the 'B' is capitalized in the Swing class name but not in the AWT class name. CheckboxMenuItem
JCheckBoxMenuItem
Note the 'B' is capitalized in the Swing class name but not in the AWT class name. Also, note that Swing menu components are true components. Choice
JComboBox
Replace a Choice
with an uneditable (the default)JComboBox
. You might have to re-write code that handles item events. Refer to Converting Choices.Dialog
JDialog
or
JOptionPane
AWT programs add components directly to a dialog and directly set its layout manager. In contrast, Swing programs add components to and set the layout manager on a JDialog
's content pane.FileDialog
JFileChooser
FileDialog
is a dialog, whileJFileChooser
is a component that you can place in any top-level container. For convenience,JFileChooser
provides methods that make it easy to put a file chooser in a dialog.Frame
JFrame
AWT programs add components directly to the frame and directly set its layout manager. In contrast, Swing programs add components to and set the layout manager on a JFrame
's content pane.Label
JLabel
A Swing label can include an image and/or text. To support accessibility, use setLabelFor
to associate each label with the component it describes (if any).List
JList
AWT lists and swing lists differ in many ways. See Converting Lists for information and examples. Menu
JMenu
Swing menu components are true components. MenuBar
JMenuBar
Swing menu components are true components. MenuItem
JMenuItem
Swing menu components are true components. Panel
JPanel
PopupMenu
JPopupMenu
Swing menu components are true components. Scrollbar
JScrollPane
or
JSlider
or
JProgressBar
ScrollPane
JScrollPane
TextArea
JTextArea
Typicaly, requires some re-coding to convert. See Converting Text Components for information and examples. TextField
JTextField
For simple uses, JTextField
is source-compatible withTextField
. If you useTextListener
s you need to modify your code to use a different type of listener. If you need a password field, useJPasswordField
instead. See Converting Text Components for information about non-trivial conversions and examples.Window
JWindow
or
JToolTip
[PENDING: use a non-window component (e.g. JLabel) in a top layer
![]() ![]() ![]() ![]() |
Converting to Swing |