Java Swing is a part of Java Foundation Classes (JFC) which was designed for enabling large-scale enterprise development of Java applications.
Java Swing is a set of APIs that provides the graphical user interface (GUI) for Java programs. Java Swing is also known as the Java GUI widget toolkit.
Java Swing or Swing was developed based on earlier APIs called Abstract Windows Toolkit (AWT). Swing provides richer and more sophisticated GUI components than AWT.
The GUI components are ranging from a simple label to a complex tree and table. Besides emulating the look and feel of various platforms, Swing also provides a pluggable look and feel to allow the look and feel of Java programs independent from the underlying platform.
Swing is a platform-independent and enhanced MVC (Model –View – Controller) framework for Java applications. Here are the most important features in Swing architecture.
- Pluggable look and feel: Swing supports several looks and feels and currently supports Windows, UNIX, Motif, and native Java metal look and feel. Swing allows users to switch look and feel at runtime without restarting the application. By doing this, users can make their own choice to choose which look and feel is the best for them instantly.
- Lightweight components: All swing components are lightweight except for some top-level containers. Lightweight means the component renders or paints itself using drawing primitives of the Graphics object instead of relying on the host operating system (OS). As a result, the application presentation is rendered faster and consumed less memory than previous Java GUI applications.
- Simplified MVC: Swing uses simplified model-view-architecture (MVC) as the core design behind each component called model-delegate. Based on this architecture, each swing component contains a model and a UI delegate. A UI delegate wraps a view and a controller in MVC architecture, as in the picture below. UI delegate is responsible for painting screens and handling GUI events. Model is in charge of maintaining information or states of the component.
Here is the short description of each package in Java Swing:
|javax.accessibility||Supports assistive technologies which help people with disabilities adapt to the Java applications, including audible text reader and screen magnification.|
|javax.swing||Contains core swing components, including most of the model interfaces and helper classes.|
|javax.swing.border||Contains classes for different kinds of borders wrapping around components.|
|javax.swing.colorchooser||Provides color dialog chooser to allow users to choose a wide range of colors using a visual interface.|
|javax.swing.event||Defines listeners and events, which swing components use to communicate asynchronously between objects of classes.|
|javax.swing.filechooser||Contains classes to support file chooser dialog to allow the user to choose files and directories.|
|javax.swing.plaf||PLAF stands for the pluggable look and feel. It contains a wide range of classes and interfaces to support a pluggable look and feel.|
|javax.swing.table||Contains classes to support data manipulation in table or spreadsheet format.|
|javax.swing.text||Contains classes and interfaces that are supporting a well-known design known as document/view.|
|javax.swing.text.html||Supports reading and formatting HTML text through the editor.|
|javax.swing.text.html.parser||Contains classes and interfaces for HTML parsing.|
|javax.swing.text.rtf||Supports reading and formatting Rich Text Format (RTF) text through the editor.|
|javax.swing.tree||Contains classes and interfaces to define models and views for a hierarchical tree component.|
|javax.swing.undo||Contains classes and interfaces supporting undo-able functionality.|