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

    Java Swing JLabel

    Overview

    In this tutorial, we will learn about the Java Swing JLabel class. A label is a GUI component that is used as a display area for short text or an image or both. The Swing label does not react to user input events.

    Swing JLabel

    We can create a label using the JLabel class. We can import the class using the following statement:

    import javax.swing.JLabel;

    To create a label, we need to instantiate the class. For example,

    JLabel label = new JLabel(“Java Swing Tutorial”,JLabel.CENTER);

    Java Program

    package com.testingdocs.swing.components;
    
    /**********************************************
     * FileName: JLabelDemo.java
     * Package : com.testingdocs.swing.components
     * 
     * Java Tutorials - www.TestingDocs.com
     **********************************************/
    
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    
    public class JLabelDemo {
    
     public static void main(String[] args) {
     //Create a Label GUI component
     JLabel label = new JLabel("Java Swing Tutorials",JLabel.CENTER);
     //Create a Frame
     JFrame frame = new JFrame("JLabel - www.TestingDocs.com");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.setSize(500,500);
     //add the label GUI component
     frame.getContentPane().add(label); 
     frame.setVisible(true);
     }
     }

    Sample Swing program

    Output

    Run the program to view the output.

    Swing JLabel

    The output frame with a label aligned to the center should be displayed.

    That’s it.

    —

    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

    ‹ Java Swing Layouts› Setup Layout Manager to Swing Container

    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