Swing has more components, a pluggable look and feel, a consistent appearance across platforms and a cleaner model-view design than AWT. Swing components are lightweight, drawn by Java itself, while AWT components wrap native widgets. Both are legacy desktop toolkits today, and new Java desktop work often uses JavaFX or a web UI instead.
AWT (Abstract Window Toolkit) shipped with Java 1.0. Swing was added in Java 1.2 and builds on AWT's event model and base classes. Swing is still part of the JDK (the java.desktop module), so existing applications keep working.
| Feature | AWT | Swing |
|---|---|---|
| Package | java.awt | javax.swing |
| Components | Heavyweight, backed by native peers | Lightweight, painted by Java |
| Look and feel | Native look of the OS | Pluggable: Metal, Nimbus, system, custom |
| Component set | Small: button, label, text field | Rich: tables, trees, tabbed panes, spinners |
| Architecture | Basic | Model-view (MVC style) per component |
| Threading | Not thread safe | Not thread safe; use the Event Dispatch Thread |
| Naming | Button | JButton |
AWT delegates drawing to the operating system, so a Button looks and sometimes behaves differently on each platform. Swing draws its own components, so layout and behaviour are the same everywhere.
You can switch the appearance of the whole application without changing component code.
Call this before creating any component. UIManager.getSystemLookAndFeelClassName() gives the native look when you want it.
Swing adds JTable, JTree, JTabbedPane, JSplitPane, JSpinner, JColorChooser, JFileChooser, JProgressBar, tool tips and borders. AWT has no equivalent for most of these.
Components such as JTable and JList separate data (TableModel, ListModel) from rendering (cell renderers), so you can change either independently.
Components can hold icons and HTML-like text, accept custom borders and renderers, and support accessibility through the Java Accessibility API.
SwingUtilities.invokeLater builds the UI on the Event Dispatch Thread, which is required because Swing is not thread safe. Use SwingWorker for long tasks so the window does not freeze. Note that Swing still uses AWT for layout managers, events and Graphics, so you import from both packages.
Mixing heavyweight AWT components with lightweight Swing ones in the same container can cause z-order problems, where the AWT component draws over Swing popups. Use Swing equivalents (JButton, JLabel, JTextField) throughout.
No. AWT is still part of the JDK and Swing depends on it for events, layout and graphics. Only specific old APIs and the Applet API are deprecated or removed.
They have no native peer; Java paints them. AWT components, in contrast, are heavyweight because each maps to an OS widget.
Yes, for layout managers, events and graphics. Avoid mixing heavyweight AWT components with Swing components in one container.
For maintaining existing applications, Swing. For a new desktop application, consider JavaFX or a web technology.
Swing improves on AWT with lightweight, consistent components, a pluggable look and feel, a far larger component set and a model-view design. Build and update Swing UIs on the Event Dispatch Thread, and consider JavaFX or a web UI for new projects.