CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > JFrame 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

JFrame in Java Swing

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

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: March 5, 2021 · 1 min read · 0 Comments
Share: X in 🔗

JFrame is a class in the Java Swing library. It is used to create a windowed graphical user interface (GUI) in a Java program. It provides a framework for building graphical user interfaces by providing methods for creating and manipulating various graphical components such as buttons, labels, text fields, and other controls.

JFrame is a top-level container that serves as the main window of a Java GUI application. It has a title bar, a border, and can be resized, maximized, minimized, and closed by the user. We can add various other components to the JFrame, such as buttons, text fields, labels, and menus.

To create a JFrame, we first create an instance of the class, set its properties such as title and size, add other components to it, and then display it using the setVisible() method.

Following is an example code that creates a JFrame and displays a GUI as an output.

import javax.swing.JFrame;

public class JFrameDemo {
	public static void main(String[] args) {
		JFrame frame = new JFrame("Hello World"); // create a new JFrame
		frame.setSize(300, 200); // set its size
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set default close operation
		frame.setVisible(true); // show the JFrame
	}
}

Output:

JFrame in Java Swing

Related Posts:

  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Interface in Java: Mastering Abstraction and…
  • Control Statements in Java
  • Compile and Run Java Program
  • Java Swing Tutorial
  • Command Line Arguments in Java
Tags:javaswing
Was this article helpful?
← Previous ArticleJCheckBox in Java Swing
Next Article →JTextField in Java Swing

Recent Posts

  • 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
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

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

Quick Links

  • About
  • Contact

Popular Topics

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