CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > First Program in Java Swing

Swing Tutorial

  • What Is Java Swing
  • First Program
  • What is AWT
  • Advantages of Swing Over AWT
  • JFrame
  • Swing Components
  • JLabel
  • JTextField
  • JPasswordField
  • JButton
  • Event Handling
  • FlowLayout
  • BorderLayout
  • GridLayout
  • GridBagLayout
  • BoxLayout
  • JPanel
  • JCheckBox
  • JRadioButton
  • Border Component
  • JComboBox
  • JList
  • JList with MVC
  • Mouse Event
  • Key Event
  • JMenuBar
  • JTextArea
  • Using Color
  • Use Font
  • Display Image/Icon
  • Dialog Box
  • JTable
  • JDesktopPane and JInternalFrame
  • JDesktopPane
  • JInternalFrame
  • Adapter Classes
  • Swing Timer
  • JScrollPane
  • JSlider
  • JProgressBar
  • JSeparator
  • JToolBar
  • ActionListener
  • ItemListener
  • Worker Thread
  • Nimbus Look and Feel

First Program in Java Swing

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 5, 2026 · 1 min read · 0 Comments
Share: in X

In this example, we are going to use the Swing library to create a simple graphical user interface (GUI) application to write the first program in Java Swing. The program creates a JFrame (window) and a JLabel (text label), and adds the label to the frame. The frame is then sized, and we will set it to close the application when the user closes the frame. Finally, we make the frame visible to the user.

You’ll need to have Java and a development environment set up to compile and run this code. Make sure to import the necessary libraries, which are part of the Java Standard Library.

import javax.swing.JFrame;
import javax.swing.JLabel;

public class HelloWorldSwing {
	public static void main(String[] args) {
		JFrame frame = new JFrame("Hello World Swing");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(300, 300);

		JLabel label = new JLabel("Hello, World!");
		frame.getContentPane().add(label);

		frame.setVisible(true);

	}
}

Output:

First Program in Swing Java

Related Posts:

  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Control Statements in Java
  • Install and Set Up Java Development Environment
  • Packages in Java: A Guide to Modular, Maintainable Code
  • What is Java? Exploring Its Key Features, Benefits,…
  • Compile and Run Java Program
Tags:guijavaswing
Was this article helpful?
← Previous ArticleWhat is AWT in Java?
Next Article →Java Swing Tutorial

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap