0% found this document useful (0 votes)
3 views3 pages

Components

The document is a reference guide for Java Swing components, detailing key features and usage of various UI elements such as JFrame, JPanel, JLabel, JButton, and others. It provides code examples for creating and manipulating these components, along with common patterns for event handling and layout management. The guide serves as a quick reference for developers preparing for exams or working with Java Swing applications.

Uploaded by

ydgjaph
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Components

The document is a reference guide for Java Swing components, detailing key features and usage of various UI elements such as JFrame, JPanel, JLabel, JButton, and others. It provides code examples for creating and manipulating these components, along with common patterns for event handling and layout management. The guide serves as a quick reference for developers preparing for exams or working with Java Swing applications.

Uploaded by

ydgjaph
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMPONENTS

🎨 Java Swing Masterclass Reference – Exam Ready


1️⃣ JFrame – The Main Window
Feature Description

Class JFrame extends Frame (AWT).

Usage Main window for Swing applications.

Create JFrame JFrame frame = new JFrame("Title");

Set size [Link](width, height);

Close operation [Link](JFrame.EXIT_ON_CLOSE);

Visibility [Link](true);

Layouts Default: BorderLayout . Use setLayout() to change.

ContentPane Container inside JFrame where components go. Use getContentPane() to access.

2️⃣ JPanel – A Simple Container


Feature Description

Class JPanel is a container for components.

Usage Groups multiple components.

Add to JFrame [Link](panel);

Layouts Default: FlowLayout .

3️⃣ JLabel – Display Text or Image


Feature Description

Class JLabel

Create JLabel label = new JLabel("Text");

Set text [Link]("New Text");

Set image [Link](new ImageIcon("[Link]"));

Non-interactive Cannot be clicked.

4️⃣ JButton – A Clickable Button


Feature Description

Class JButton

Create JButton btn = new JButton("Click Me");

Add action [Link](e -> {});

Get text [Link]();

5️⃣ JTextField – Single-Line Text Input


Feature Description

Class JTextField

Create JTextField tf = new JTextField(20);

Get text [Link]();

Set text [Link]("Hello");

COMPONENTS 1
6️⃣ JPasswordField – Hidden Input (Password)
Feature Description

Class JPasswordField

Create JPasswordField pf = new JPasswordField(20);

Get password [Link](); (returns char[] )

7️⃣ JTextArea – Multi-Line Text Input


Feature Description

Class JTextArea

Create JTextArea ta = new JTextArea(5, 20);

Get text [Link]();

Set text [Link]("Hello");

Scrollbars Wrap in JScrollPane .

8️⃣ JComboBox – Drop-Down Selection


Feature Description

Class JComboBox

Create JComboBox<String> cb = new JComboBox<>(items);

Get selection [Link]();

Add item [Link]("New Item");

Set editable [Link](true);

9️⃣ JList – Vertical List of Items


Feature Description

Class JList

Create JList<String> list = new JList<>(items);

Selection modes SINGLE_SELECTION , MULTIPLE_INTERVAL_SELECTION

Get selection [Link](); or [Link]();

Scroll Always wrap in JScrollPane .

🔟 JCheckBox – Multiple Toggle Options


Feature Description

Class JCheckBox

Create JCheckBox cb = new JCheckBox("Option");

Get state [Link]();

Set state [Link](true/false);

1️⃣1️⃣ JRadioButton – Single Selection Option


Feature Description

Class JRadioButton

Create JRadioButton rb = new JRadioButton("Option");

Grouping Use ButtonGroup to group.

Get state [Link]();

🔑
COMPONENTS 2
🔑 Common Patterns
Action Code Example

Adding to JFrame [Link](component);

Adding to JPanel [Link](component);

Handling Events (e.g., clicks) [Link](e -> { });

Creating layout [Link](new FlowLayout());

Scrollable components new JScrollPane(component)

Set visibility [Link](true);

Get component data .getText() , .getSelectedItem() , .isSelected()

COMPONENTS 3

You might also like