HOWTO · Java
Best GUI Builders for Java Swing Applications
Compare the two classic GUI builders for Java Swing applications: WindowBuilder in Eclipse and the GUI builder built into Apache NetBeans — how to install WindowBuilder and how to start a Swing form in each.
On this page
A good GUI builder lets you design a window visually — placing components by drag and drop, previewing the layout as you work, and letting the tool generate the boilerplate code — instead of writing every layout line by hand. For Java Swing, the two classic choices are WindowBuilder, an Eclipse plugin, and the GUI builder built into Apache NetBeans.
GUI building has its own group in the Java Tutorial, which maps the Swing and JavaFX guides for desktop Java.
In this article, we first look at why Swing is used and how its classes are organized. We then install WindowBuilder in Eclipse and create a Swing window with it, and finally do the same with the NetBeans GUI builder.
Why Do We Use Java Swing
Swing is the standard toolkit for building window-based desktop applications in Java. It ships with the Java platform itself, is open source, and provides a complete set of components — buttons, lists, text fields, tables, and more — that a GUI builder can place on a form and generate code for.
Classification of Java Swing Class
To understand Java Swing more clearly, please see the following diagram.
Diagram Summary:
The diagram depicts the relationship between a Java object at the top and a JFrame at the bottom.
Almost every component you interact with — lists, buttons, text fields, and so on — inherits from the JComponent class, which itself descends from the AWT Container and Component classes. The top-level containers are the exception: JFrame and JDialog extend the AWT window classes (Frame and Dialog) rather than JComponent, because they are the windows the operating system manages.
All key Swing elements are included in the foundation within one’s graphical user interface app.
Windows Builder Eclipse Plugin
WindowBuilder is an Eclipse plugin that integrates SWT Designer and Swing Designer into a single package. Its WYSIWYG visual designer provides layout tools to create anything from simple forms to complex windows: you add controls by drag and drop, edit their properties in a properties editor, and wire up event handling, while WindowBuilder generates the corresponding code for you.
WindowBuilder Plugin:
Follow These Steps:
-
Installation: WindowBuilder
-
Add to Eclipse (drag-and-drop):
-
Confirm the installation process:
Install Windows Builder Plugin From Eclipse Marketplace
The drag-and-drop install above is the quickest route. You can also install WindowBuilder from inside Eclipse, through the update mechanism:
You have to start your Eclipse and see what version it is.
-
Then go to
Help. -
Select
Install New Software. -
Search for your Eclipse version.
-
Click on
General Purpose Tools. -
Check all the Windows Builder features you want to install.
-
Once you have checked all the options, confirm and wait for the installation process to finish.
-
Do not forget to restart Eclipse after the installation has finished.
Use Windows Builder for Swing GUI Development
After installing WindowBuilder, create a Swing application window like this:
Do the following steps:
-
Go to
File. -
Choose
New. -
Other -
Search
WindowBuilder=>Swing Designer=>Application Window.
The new class opens in the WindowBuilder design view, where you build the window visually and switch to the source view to see the generated code.
NetBeans Java Swing GUI Builder
The NetBeans GUI Builder supports the production of sophisticated and elegant graphical user interface applications, and it is built into the IDE — there is nothing extra to install. You also don’t need deep expertise in layout management: the builder works with the GroupLayout manager and guides alignment as you place components.
What does this IDE offer?
- Open Source
- Layout Management
- Container-based lightweight development
- Availability of Null layouts
- Powerful customization
- Drag-and-drop features
- Easy to use
First, you need to download Apache NetBeans IDE if you have not.
-
Download: NetBeans
-
Once downloaded, launch and create a new project.
-
After that, type your project name and finish.
-
Once you have created a new project, you need to create a class. Right-click on your project >
new>JFrame Form.
JFrame Form (rather than a plain class) is what opens the visual designer; NetBeans will generate the following code dynamically after finishing it.public class Demo2 extends javax.swing.JFrame {
public Demo2() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE));
pack();
} // </editor-fold>
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Demo2.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Demo2.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Demo2.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Demo2.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Demo2().setVisible(true);
}
});
}
}
The generated class is a complete, runnable JFrame: the guarded initComponents() block is maintained by the builder as you design, and the main method sets the Nimbus look and feel (when available) and shows the form. You design in the visual editor and let NetBeans keep this code in sync.
Both builders generate plain Swing code, so the choice between them is mostly a choice of IDE: WindowBuilder if you work in Eclipse, the built-in builder if you work in NetBeans. Either way, you get a visual designer, drag-and-drop component placement, and generated code you can still read and adjust by hand.