Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. It is a part of the JFC (Java Foundation Classes). It is build on top of the AWT API and entirely written in Java. It is platform independent unlike AWT and has lightweight components.
Here you can see the hierarchy of Java Swing classes:
A Swing application must contain at least one container class. Here are three types of container classes:
- Panel: It is used to organize components on to a window
- Frame: A fully functioning window with icons and titles
- Dialog: It is like a pop up window but not fully functional like the frame
Here are the most used methods of component class:
Here an example of the program’s beginning in Swing:
Since Java Swing is platform independant, lightweight, has more powerful components than AWT and follows the Model View Controller (MVC) where model represents data, view represents presentation and controller acts as an interface between model and view, it is very much used until today.