Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Converting to Swing

Swing Replacements for AWT Components

Use the following table as a guide for choosing a Swing replacement for each AWT component used in your program.

AWT ComponentClosest Swing EquivalentNotes
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 You populate a JComboBox differently than a Choice. See Converting Choices for details and an example.
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  
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 You populate a Swing list differently than an AWT list. Additionally, you typically need to put a Swing list in a scroll pane, whereas AWT lists supported scrolling directly. 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 Requires some re-coding to convert. See Converting Text Components for information and examples.
TextField JTextField For simple uses, JTextField is source-compatible with TextField. If you use TextListeners you need to modify your code to use a different type of listener. If you need a password field, use JPasswordField 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


Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Converting to Swing