EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Java Swing Tutorial

Home Software Development Software Development Tutorials Java Swing Tutorial

Basic

What is Swing?

Swing Components in Java

Swing Program in JAVA

Java Swing Layout

Graphics in Java Swing

Timer in Java Swing

Controls

JButton in Java

JFrame in Java

JTextArea in Java

JTextField in Java

JCheckBox in Java

JLabel in Java

JTable in Java

JSlider

JList in Java

JMenu

Jpasswordfield

JOptionPane in Java

JPanel in Java

JPopupMenu

JProgressBar

JScrollPane in Java

JLayeredPane

JDesktopPane

JColorChooser

JComboBox in Java

JComponent in Java

JDialog in Java

JEditorPane

JFileChooser in Java

JTabbedPane in Java

JTextPane

JToggleButton

JToolBar

JTree in Java

Java Swing Button

JSpinner

JSplitPane

Layout

Layout in Java

Layout Manager in Java

Flowlayout in Java

Grid Layout in Java

GridBagLayout in Java

Gridlayout in Java

GroupLayout in Java

SpringLayout in Java

BorderLayout in Java

BoxLayout in Java

CardLayout in Java

Java Swings Tutorial

Java swing consists of components or widgets to develop Graphical User Interface Applications. Java swing is a part of JFC (Java Foundation Class). JFC consists of AWT, swing, and java2D. There are two types of widget toolkits Light Weight and Heavy Weight. Java Swing is Lightweight GUI Toolkit that includes Buttons, Textboxes, etc...…

Java Swing components are platform-independent. Swing is a pluggable look and feels swing that follows the MVC framework. In Java Swing Container class plays an important role. The container class holds all the widgets. A container class is divided into three type's panels, Frame, and Dialog.

Why do we need to learn Java Swing?

To develop a java GUI application, Java Swing and AWT support two technologies. Compared with java, AWT swing is richer in terms of components. Swings provide additional functionalities and added components to replace AWT. A most important feature of the swing is its components are platform-independent. Java swing uses the MVC framework. Thus, it provides a more flexible UI. Swing components are lightweight components. Java swings are built-in double buffering. Swing components are different looks and feel.

Applications of Java Swing

Java swing is used to develop desktop applications like billing or inventory applications and real-time applications to manage and control mechanical devices. Swings are also used to develop mobile applications like gaming, calculators, etc.…

It also supports developing a network-based application to manage clients in the network. These are very few examples of java swing uses since it's platform-independent. These benefits develop applications that run on any platform.

Example of Java Swing Program

Simple java swing program to create a form for Student Registration.

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class StudentRegistration
{
public static void main(String[] args) {
Frame frame = new JFrame("Student Registration");
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel)
{
panel.setLayout(null);
JLabel userLabel1 = new JLabel("First Name");
userLabel1.setBounds(10,20,80,25);
panel.add(userLabel1);
JLabel userLabel2 = new JLabel("Last Name");
userLabel2.setBounds(10,50,100,25);
panel.add(userLabel2);
JLabel userLabel3 = new JLabel("Email ID");
userLabel3.setBounds(10,80,80,25);
panel.add(userLabel3);
JLabel userLabel4 = new JLabel("Phone No.");
userLabel4.setBounds(10,110,80,25);
panel.add(userLabel4);
JTextField fname = new JTextField(20);
fname.setBounds(100,50,165,25);
panel.add(fname);
JTextField lName = new JTextField(20);
lName.setBounds(100,20,165,25);
panel.add(lName);
JTextField email = new JTextField(20);
email.setBounds(100,80,165,25);
panel.add(email);
JTextField phNO = new JTextField(20);
phNO.setBounds(100,110,165,25);
panel.add(phNO);
JButton loginButton = new JButton("Register");
loginButton.setBounds(10, 160, 80, 25);
panel.add(loginButton);
JButton clearButton = new JButton("clear");
clearButton.setBounds(100, 160, 80, 25);
panel.add(clearButton);
}
}

Output:

Java Swing Program Output

Prerequisites

Some basic knowledge about java programming and listening is a must while working with java swing. A Java event listener of AWT components and packages is necessary to some extent. Basic knowledge regarding form designing and alignment is also required. Netbeans IDE is well suited to developing desktop GUI applications targeting swings.

Target Audience

The target audience includes soft professionals and beginners who are willing to learn java swings. Since it's easier to design GUI applications compared to AWT for beginners who are eager to learn from design or desktop applications, swings are the easiest way.

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More