Swing (Java)

Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT).

In December 2008, Sun Microsystems (Oracle's predecessor) released the CSS / FXML based framework that it intended to be the successor to Swing, called JavaFX.

[3] The Internet Foundation Classes (IFC) were a graphics library for Java originally developed by Netscape Communications Corporation and first released on December 16, 1996.

On April 2, 1997, Sun Microsystems and Netscape Communications Corporation announced their intention to incorporate IFC with other technologies to form the Java Foundation Classes.

Originally distributed as a separately downloadable library, Swing has been included as part of the Java Standard Edition since release 1.2.

JavaFX is replacing Swing owing to several advantages, including being more lightweight, having CSS styling, sleek design controls, and the use of FXML and Scene Builder.

[8] Members of the Java Client team that was responsible for Swing included James Gosling (Architect), Rick Levenson (manager), Amy Fowler & Hans Muller (co-technical leads), Tom Ball, Jeff Dinkins, Georges Saab,[9] Tim Prinzing, Jonni Kanerva, and Jeannette Hung & Jim Graham (2D Graphics).

Swing objects asynchronously fire events, have bound properties, and respond to a documented set of methods specific to the component.

Swing's heavy reliance on runtime mechanisms and indirect composition patterns allows it to respond at run time to fundamental changes in its settings.

Swing's high level of flexibility is reflected in its inherent ability to override the native host operating system (OS)'s GUI controls for displaying itself.

This allows Swing to plug into the host OS's GUI management framework, including the crucial device/screen mappings and user interactions, such as key presses or mouse movements.

This transposition and decoupling is not merely visual, and extends to Swing's management and application of its own OS-independent semantics for events fired within its component containment hierarchies.

In general, only complex components, such as tables, trees and sometimes lists, may require the custom model implementations around the application-specific data structures.

To get a good sense of the potential that the Swing architecture makes possible, consider the hypothetical situation where custom models for tables and lists are wrappers over DAO and/or EJB services.

(Conceptually, this view of the layout management is quite similar to that which informs the rendering of HTML content in browsers, and addresses the same set of concerns that motivated the former.)

Since early versions of Java, a portion of the Abstract Window Toolkit (AWT) has provided platform-independent APIs for user interface components.

By contrast, Swing components are often described as lightweight because they do not require allocation of native resources in the operating system's windowing toolkit.

Once the frame is displayed, exiting the main method does not cause the program to terminate because the event dispatching thread remains active until all of the Swing top-level windows have been disposed.

Although Swing code can be run without using this technique (for instance, by not implementing Runnable and moving all commands from the run method to the main method), it is considered to be good form, as Swing is not thread-safe, meaning that invoking resources from multiple threads can result in thread interference and memory consistency errors.

By attaching DocumentListener interfaces, you can dynamically monitor changes in the text content, enabling real-time validation, formatting, or auto-completion of input data.

Example Swing widgets in Java
AWT and Swing class hierarchy
The basic example code running on Windows 7