TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Swing

Create a Swing Frame window

Overview

In this tutorial, we will learn how to create a Swing Frame window. A frame is a window with a title and a border.

Swing Frame

We can create a frame using the JFrame class. JFrame is a top-level Swing container that provides a place for other Swing GUI components to paint themselves.  We need to import the class using the below statement:

import javax.swing.JFrame;

Java Program

package com.testingdocs.swing.components;

/**********************************************
 * FileName: JFrameDemo.java
 * Package : com.testingdocs.swing.components
 * 
 * Java Tutorials - www.TestingDocs.com
 **********************************************/

import javax.swing.JFrame;

public class JFrameDemo {
 public static void main(String[] args) {
 // Create JFrame 
 JFrame frame = new JFrame("JFrameDemo - www.TestingDocs.com");
 //Frame properties
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setSize(600, 400);
 frame.setVisible(true);
 }
}

Output

Run the Java application to view the output.

Swing Frame Window

 

JFrame frame = new JFrame(“JFrameDemo – www.TestingDocs.com”);

Create a frame with title the ‘FrameDemo – www.TestingDocs.com’

frame.setSize(600, 400);

Set the size for the window. The width and the height of the window.

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

Make the application quit when the close box is clicked

frame.setVisible(true);

The setVisible will display the windows on the screen. This call also starts a separate thread to monitor user interaction with the window user interface. Even if the main method returns, the execution continues because the setVisible() call creates another execution thread.

The frame window can be resized and dragged. Users can also minimize, maximize or close the window.

—

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Add GUI Components Swing

Java Swing /

Add GUI Components to a Swing Container

JPanel Container Class

Java Swing /

Swing JPanel Container Class

Swing CardLayout

Java Swing /

Java Swing CardLayout

Java Swing GridLayout

Java Swing /

Java Swing GridLayout

Java Swing FlowLayout

Java Swing /

Java Swing FlowLayout

‹ Swing JCheckBox Class› Java Swing Layouts

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version