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

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com