Introduction Java Swing

last modified July 7, 2020

This is an introductory Swing tutorial. The purpose of this tutorial is to get you started with the Java Swing toolkit. The tutorial has been created and tested on Linux.

About Swing

Swing library is an official Java GUI toolkit released by Sun Microsystems. It is used to create Graphical user interfaces with Java.

Swing toolkit is:

Swing is an advanced GUI toolkit. It has a rich set of widgets. From basic widgets like buttons, labels, scrollbars to advanced widgets like trees and tables. Swing itself is written in Java.

Swing is a part of JFC, Java Foundation Classes. It is a collection of packages for creating full featured desktop applications. JFC consists of AWT, Swing, Accessibility, Java 2D, and Drag and Drop. Swing was released in 1997 with JDK 1.2. It is a mature toolkit.

The Java platform has Java2D library, which enables developers to create advanced 2D graphics and imaging.

There are basically two types of widget toolkits:

A heavyweight toolkit uses OS's API to draw the widgets. For example Borland's VCL is a heavyweight toolkit. It depends on WIN32 API, the built-in Windows application programming interface. On Unix systems, we have a GTK+ toolkit, which is built on top of X11 library. Swing is a lightweight toolkit; it paints its own widgets. Similarly does the Qt5 toolkit.


In 2008, a new Java GUI toolkit was released. It was created in order to address new demands in graphical computing such as advanced animations and mulitouch support.

JavaFX is a software platform for developing and delivering rich internet applications (RIAs) that can run across a wide variety of devices. JavaFX is the next generation GUI toolkit for the Java platform. It is fully integrated with recent versions of Java SE Runtime Environment (JRE) and the Java Development Kit (JDK).

This was an introduction to Java Swing.