EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up

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

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Company
  • About us
  • Alumni Speak
  • Contact Us
  • Log in
  • Sign up
Work with us
  • Careers
  • Become an Instructor
EDUCBA for Enterprise
  • Enterprise Solutions
  • Explore Programs
  • Free Courses
  • Free Tutorials
  • EDUCBA at Coursera
  • EDUCBA at Udemy
Resources
  • Blog
  • Self-Paced Training
  • ExamTurf
  • Verifiable Certificate
  • Popular Skills Catalogue
  • Exam Prep Catalogue
Popular Categories
  • Lifetime Membership
  • All in One Bundles
  • Featured Skills
  • New & Trending
  • Fresh Entries
  • Finance
  • Data Science
  • Programming and Dev
  • Excel
  • Marketing
  • HR
  • PDP
  • VFX and Design
  • Project Management
  • Exam Prep
  • Learning Paths @ $49
  • All Courses
  • Terms & Conditions
  • Disclaimer
  • Privacy Policy & Cookie Policy
  • Shipping Policy

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW