BCA / B.Tech 9 min read

What is Java Swing and its methods

Quick Summary & Key Takeaways

  • • Subject Focus: Java Notes in English (BCA / B.Tech Syllabus)
  • • Core Topic: What is Java Swing and its methods - General Topics
  • • Overview: table { width: 100%; border-collapse: collapse; } table, th, td { border: 1px solid #ddd; padding: 8px; } th { background-color: #f2f2f2; } What is Jav...
  • • Key Concepts: Java Swing, Java Swing components, Java Swing methods, Java GUI development, Java Swing tutorial Hindi, Java Swing examples, Java Swing features,

What is Java Swing?

Java Swing is a part of the Java Foundation Classes (JFC) used to create window-based applications.

It is built on top of the AWT (Abstract Windowing Toolkit) API and is written entirely in Java.

Use of Java Swing

The Swing API is used by developers to create Java-based Front End/GUI applications. The Swing API is used as a substitute for the AWT API.

In Java, the Javax.swing package provides classes for the Swing API such as:

  • JButton
  • JComboBox
  • JList
  • JTabbedPane
  • JToolbar
  • JTextArea
  • JRadioButton
  • JPasswordField

Properties of Java Swing

1. Platform Independent

Swing components are platform-independent, meaning they can run on any operating system.

2. Light Weight

Since Swing components are written entirely in Java, they are light weight.

3. Controls

Swing has many good controls like:

  • Tree
  • TabbedPane
  • Slider
  • ColorPicker
  • Table Controls

4. Customize

We can easily customize Swing controls.

5. Look and Feel

The look and feel of a Swing-based application can also be changed at runtime.

Methods of Java Swing Components Classes

MethodDescription
public void add(Component c)It is used to add one component to another component.
public void setSize(int width, int height)It is used to set the size of the component.
public void setLayout(LayoutManager m)It is used to set the Layout Manager for the component.
public void setVisible(boolean b)It is used to set the visibility of the component.

A Simple Program of Java Swing


import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class App {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("Hello World Swing!");
                frame.setSize(500, 400);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
            }
        });
    }
}

In this article, we learned what Java Swing is, its properties, and its various methods. Hope this information proves useful for you.

Frequently Asked Questions (FAQs)

table { width: 100%; border-collapse: collapse; } table, th, td { border: 1px solid #ddd; padding: 8px; } th { background-color: #f2f2f2; } What is Java Swing?.
Understanding What is Java Swing and its methods is fundamental to mastering Java Notes in English. It covers crucial concepts, solved problems, and revision points essential for academic and entrance exam success.
You can read free solved examples, detailed explanations, and key formulas for What is Java Swing and its methods directly on the NotesMedia website or by downloading the NotesMedia App.