|      | Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form | 
 
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.AppletJAppletAWT applets and Swing applets differ in several ways. See Converting Applets. ButtonJButtonA Swing button can include an image and/or text. CanvasJPanel,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. CheckboxJCheckBoxor
JRadioButtonNote the `B' is capitalized in the Swing class name but not in the AWT class name. CheckboxMenuItemJCheckBoxMenuItemNote 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. ChoiceJComboBoxReplace a Choicewith an uneditable (the default)JComboBox. You might have to re-write code that handles item events. Refer to Converting Choices.DialogJDialogor
JOptionPaneAWT-based programs add components directly to a dialog and directly set its layout manager. In contrast, Swing-based programs add components to and set the layout manager on a JDialog's content pane.FileDialogJFileChooserFileDialogis a dialog, whileJFileChooseris a component that you can place in any top-level container. For convenience,JFileChooserprovides methods that make it easy to display a file chooser in a dialog.FrameJFrameAWT-based programs add components directly to a frame and directly set its layout manager. In contrast, Swing-based programs add components to and set the layout manager on a JFrame's content pane.LabelJLabelA Swing label can include an image and/or text. To support accessibility, use setLabelForto associate each label with the component it describes (if any).ListJListAWT lists and Swing lists differ in many ways. See Converting Lists for information and examples. If you'd like your list to display multiple columns of information, consider upgrading to a table. If the list contains hierarchical informaiton, consider using a tree. MenuJMenuSwing menu components are true components. MenuBarJMenuBarSwing menu components are true components. MenuItemJMenuItemSwing menu components are true components. PanelJPanelYou can easily add borders to Swing panels. PopupMenuJPopupMenuSwing menu components are true components. ScrollbarJScrollPaneor
JSlideror
JProgressBarAlthough Swing has a JScrollBarclass, you don't usually use it directly.ScrollPaneJScrollPaneYou can add custom decorations, including row and column headers, to Swing scroll panes. TextAreaJTextAreaTypically requires some re-coding to convert. See Converting Text Components for information and examples. TextFieldJTextFieldFor simple uses, JTextFieldis source-compatible withTextField. If you use text listeners you need to modify your code to use a custom document or document listener instead. If you need a password field, useJPasswordFieldinstead. See Converting Text Components for information about non-trivial conversions and examples.WindowJWindowor
JToolTipYou might be able to substitute a non-window component, such as a JLabel, and use a layered pane.
 
|      | Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form | 
Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.