Java GUI Example: Build Stunning Desktop Apps Fast

Robert Jul 13, 2026

Java offers robust support for GUI development through several libraries and frameworks like Swing, JavaFX, and AWT. With the right tools and understanding, Java developers can create intuitive and engaging user interfaces. Let's explore a simple Java GUI example using Swing to create a basic "Hello, World!" application.

Basic GUI in Java | Swing GUI Tutorial for Beginners
Basic GUI in Java | Swing GUI Tutorial for Beginners

Swing is a popular choice due to its rich components, flexibility, andcloser integration with the Java platform. It provides a wide range of controls, containers, and other GUI elements. Before we begin, ensure you have Java Development Kit (JDK) version 8 or higher installed on your machine.

screenshot of the windows file window with text and numbers highlighted in each section,
screenshot of the windows file window with text and numbers highlighted in each section,

Setting Up the Java GUI Project

The first step is to set up a new Java project in your favorite IDE. Here, we'll use IntelliJ IDEA as an example. Open IntelliJ, select 'New Project,' and choose 'Java.' Name your project "java-gui-example" and select 'Next.'

Java Swing UI Redone
Java Swing UI Redone

Choose 'Empty Java Project' and click 'Next.' Then, click 'Finish' to create the project.

Creating the User Interface

Java Swing Tutorial: How to Create a GUI Application in Java
Java Swing Tutorial: How to Create a GUI Application in Java

In this example, we'll create a simple JFrame containing a JLabel with "Hello, World!" text. Right-click on your project in the 'Project' view, select 'New,' then 'JFrame Form.' Name it "MainForm" and choose the 'Bounds' layout. Click 'Next,' then 'Finish.'

In the 'Design' view, you'll see a blank JFrame. In the 'Components' palette, drag and drop a 'JLabel' onto the JFrame. In the 'Properties' view, set the JLabel's text to "Hello, World!" Also, change the JFrame's title to "Java GUI Example" and set its bounds to (100, 100, 400, 400).

Implementing the Main Method

Java GUI development using AWT
Java GUI development using AWT

Now, let's implement the main method to run our GUI application. Open the "Main" class (if not already open) and replace its content with the following code:

```java import javax.swing.*; public class Main { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("Java GUI Example"); JLabel label = new JLabel("Hello, World!"); frame.add(label); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }); } } ```

In this code, we use SwingUtilities.invokeLater to ensure our GUI updates are executed on the Event Dispatch Thread (EDT)

That's it! Now, run your application, and you should see a JFrame with a "Hello, World!" message. This simple example serves as a starting point; Swing offers many more features and customization options for creating complex GUIs.

JavaFX Login Example - Scene builder and Netbeans
JavaFX Login Example - Scene builder and Netbeans

Exploring Swing Components

Swing provides a rich set of components for creating sophisticated user interfaces. Some popular components include JButton, JComboBox, JTextField, JTable, and JList. Let's briefly explore these components with examples.

Java Swing/GUI Cheat Sheet
Java Swing/GUI Cheat Sheet
Java Cheatsheet
Java Cheatsheet
HTML input types
HTML input types
Java Programming Tutorial - 50 - Graphical User Interface GUI
Java Programming Tutorial - 50 - Graphical User Interface GUI
C#,  JAVA,PHP, Programming ,Source Code: Java - Login And Register Form Design
C#, JAVA,PHP, Programming ,Source Code: Java - Login And Register Form Design
Java Collection Framework: ArrayList Explained Visually
Java Collection Framework: ArrayList Explained Visually
Getting Started with Java GUI Development - DZone Refcards
Getting Started with Java GUI Development - DZone Refcards
30 Days of Java – Day 17 | Java Interfaces Explained for Beginners
30 Days of Java – Day 17 | Java Interfaces Explained for Beginners
Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide
Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
Title: 🎯 Switch Case in Java Simplified!
Title: 🎯 Switch Case in Java Simplified!
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
the different types of web pages are shown
the different types of web pages are shown
a computer screen with many different colored words on it's side and blue light in the background
a computer screen with many different colored words on it's side and blue light in the background
HashMap vs HashSet in Java ⚡ Key Differences Explained (DSA Cheat Sheet)
HashMap vs HashSet in Java ⚡ Key Differences Explained (DSA Cheat Sheet)
How to design a simple dashboard UI using Swing and Java -Netbeans
How to design a simple dashboard UI using Swing and Java -Netbeans
Interface in Java
Interface in Java
Java Cheat Sheet: Operators, Scanner & User Input ☕
Java Cheat Sheet: Operators, Scanner & User Input ☕

Buttons: JToggleButton and JCheckBox

JavaFX offers various button types, two of which are JToggleButton (for checkbox-like behavior) and JCheckBox (for single-select checkboxes). Add these components to your GUI and experiment with their properties and listeners.

Combo Boxes: JComboBox and JList

JComboBox serves as a dropdown list for selecting items, while JList displays a list of items in a scrollable panel. Create combo boxes and lists with custom item renderers and event listeners. You can also exploit their binding capabilities with other components.

Java's capability for creating GUIs using Swing is vast and powerful. From complex data visualizations to web-based interfaces, the possibilities are endless. Keep exploring the numerous tutorials and resources available online to master Java GUI development.

Now that you've created your first Java GUI application, try enhancing it further. Add more Swing components, customize their appearance and behavior, and integrate them with your application's logic. Happy coding!