Introduction Java Swing

Introduction Java Swing

This is an starting Swing guide. The reason of this guide is to get you started with the Java Swing tool set. The guide has been created and examined on A linux systemunix.

About Swing

Swing selection is operate Java GUI tool set launched by Sun Microsystems. It is used to develop Visual customer connections with Java.

Swing tool set is:

system independent

The Swing API has 18 public packages:


Swing is a high level GUI tool set. It has an excellent set of icons. From primary icons like control buttons, brands, scrollbars to innovative icons like plants and platforms. Swing itself is coded in Java.

Swing is a part of JFC, Java Base Sessions. It is a assortment of offers for creating full presented pc programs. JFC comprises of AWT, Swing, Availability, Java 2D, and Swing and Fall. Swing was published in 1997 with JDK 1.2. It is an old tool set.

The Java system has Java2D selection, which allows designers to develop innovative 2D design and picture.

There are generally two types of gadget toolkits:


A high quality tool set uses OS’s API to attract the icons. For example Borland’s VCL is a high quality tool set. This will depend on WIN32 API, the built-in Windows application development customer interface. On Unix systems, we have a GTK+ tool set, which is constructed on top of X11 selection. Swing is a light-weight toolkit; it shows its own icons. In the same way does the Qt4 tool set.
SWT library

There is also another GUI selection for the Java development language. It is called the Standard Widget Toolkit (SWT). SWT selection was first created by the IBM organization. Now it is an free venture managed by the Surpass group. SWT is an example of a high quality tool set. It allows the actual OS to develop the consumer interface. SWT uses the Java local customer interface to do the job. There is a guide devoted to SWT on ZetCode.

This was an intro to Java Swing.

In this section, we will program our first Move applications. We build a first easy program, show how to cancel an program with a Stop key, show a tooltip, use mnemonics, and show conventional colors.

Java Move elements are primary foundations of a Coffee Move program. In this section we will use JFrame, JButton, and JLabel elements. JFrame is is a top-level display with a headline and a boundary. It is used to arrange other elements, known as kid elements. JButton is a force key used to carry out an action. JLabel is an element used to dispay a brief written text sequence or an picture, or both.

While this program code is very brief, the applying display can do quite a lot. It can be resized, maximised, or reduced. All the complexness that comes with it has been invisible from the applying developer.

import java.awt.EventQueue;
import javax.swing.JFrame;

Here we transfer Move sessions that will be used in the program code example.

public category SimpleEx expands JFrame {

The SimpleEx category gets from the JFrame element. JFrame is a top-level package. The primary objective of bins is to keep elements of the applying.

public SimpleEx() {


It is a good development exercise not to put the applying program code into constructors, but assign the work to a particular technique.

setTitle(“Simple example”);

Here we set the headline of the display using the setTitle() technique.

setSize(300, 200);

This program code will re-size the display to be 300px wide and 200px high.


This line will middle the display on the display.


This technique will near the display if we simply simply select the Close key of the titlebar. Automatically nothing happens if we simply simply select the key.

EventQueue.invokeLater(() -> {
SimpleEx ex = new SimpleEx();

The Java course in Pune is available in the best institute of Java in Pune.

There are many Java training class and Java training courses in Pune to make your career in this field.

Check our JAVA REVIEWS here.