Course Content‎ > ‎Session 7‎ > ‎

Intro to Swing & AWT

AWT and Swing are used for GUI programming in Java. Earlier version of Java (1.0) had a class library called AWT (Abstract Window Toolkit) for GUI programming. AWT used peer-based approach to create GUI. If you used the original AWT to put a text box on a Java window, an underlying peer text box in the background actually handled the text input.

Why is AWT not used anymore?
  1. AWT had different bugs on the different platforms.
  2. With AWT, it was difficult to write high-quality portable library that depended on user interface elements. 
  3. User interface elements like scroll bars, menus and text fields were not consistent on different platforms.
  4. Applications built using AWT lacked the look and feel of a Windows or Mac application. Also, they did not provide the same functionality.

Thus, user interface library called Swing was introduced. The Swing package is part of the JavaTM Foundation Classes (JFC) in the Java platform. The JFC encompasses a group of features to help people build GUI. Swing provides all the components from buttons to split panes and tables.

Swing is not a complete replacement of AWT. It packages a set of GUI components and gives you more capable user-interface elements. Swing adds a lot of functionality that was missing from the AWT, like support for keyboard input, copy and paste, drag and drop and focus traversal. Swing adds a more sophisticated set of events, and more advanced interface controls like an editor and scrolling panes, a tree view and a table. Swing is a standard part of Java 2 and higher.  Swing 1.1.1 is the last version of Swing, which will be compatible with JDK 1.1. You can mix the components of Swing and AWT and it's documented here: