Table of Contents
Introduction
Swing is essentially a library in JAVA that provides you with all the necessary tools to develop a GUI application in JAVA. Swing is developed by Sun Microsystems and it eventually replaced the traditional AWT (Abstract Window ToolKit). AWT and SWING are mostly used together to avail features of both the packages. The Swing is originally part of the Java Foundation Classes (JFC). These classes are the fundamentals of designing GUI based applications in Java.
Differences between Swing and AWT
Java AWT | Java Swing |
Java AWT is platform-dependent. | Swing widgets are platform-independent. This gives developers the much required freedom to work with cross-platform applications. |
AWT components are generally heavy-weight. | Swing components are light-weight. |
The ‘pluggable look and feel’ method is not supported in AWT.
| Swing supports ‘pluggable look and feel’. |
The number of widgets offered by AWT is much less compared to Swing. | Swing has in store a wide variety of widgets and components like tables, lists, etc. |
AWT does not conform to the MVC (Model – View – Controller) architecture. | Swing has adapted the MVC architecture to allow a systematic flow of data. |
Starting from labels to scrollbars to intuitive graphs, Swing offers users a lot of widgets and components that they can use in their application. For booking applications, Swing has a ready-made calendar that users can import.
JAVA FX
FX is the latest Java GUI Toolkit and it is surely and steadily gaining popularity as it is extremely easy to use and run applications on FX. FX comes fully integrated with the latest versions of JAVA SE Runtime Environment (JRE).
Some Common Swing Methods
- void add (Component c): This will add a component to your grid.
- void setSize (int width, int height): To adjust the size of a component.
- void setLayout (LayoutManager m): Used to set the type of layout.
- void setVisible (boolean b): b is true when you want a component to show on the screen.
0 Comments