Features of Swing in Java
Swing is a GUI toolkit that facilitates the creation of highly interactive GUI applications. Swing is more flexible and robust when it comes to implementing graphical components. Swing can be regarded as more graphically rich than AWT not only because they provide some entirely new graphical components like a tabbed window and tree structure. Some of the key swing classes are given as below:
Swing Class | Description |
---|---|
JApplet | It is an extension of Applet class, it is the swing's version of the applet. |
JFrame | It is an extension of java.awt.Frame class, it is the swing's version of the frame. |
JButton | It helps to realize a push button in the swing. |
JTabbedPane | It helps to realize a tabbed pane in the swing. |
JTree | It helps to realize a hierarchical tree or structure in the swing. |
JComboBox | It helps to realize a combo box in the swing. |
A Swing GUI consists of two key items:
-
1. Components
2. Containers
Components:
In Swing, Components are derived from the JComponent class where JComponent provides the functionality that is common to all components.
Example: JComponent supports the pluggable look and feel.
Containers:
JComponent inherits the AWT classes Container and Component. Thus, a Swing component is built on and compatible with an AWT component. All of Swing’s components are represented by classes defined within the package [java]javax.swing[/java].
A Container holds a group of components. Thus, a container is a special type of component that is designed to hold other components. Thus, all Swing GUIs will have at least one container. Because containers are components, a container can also hold other containers.
Swing Packages:
Swing is a very large subsystem and makes use of many packages. These are the packages used by Swing are given below:
javax.swing | javax.swing.border | javax.swing.colorchooser |
javax.swing.event | javax.swing.filechooser | javax.swing.plaf |
javax.swing.plaf.basic | javax.swing.plaf.metal | javax.swing.plaf.multi |
javax.swing.plaf.synth | javax.swing.table | javax.swing.text |
javax.swing.text.html | javax.swing.text.html.parser | javax.swing.text.rtf |
javax.swing.tree | javax.swing.undo |