SECTION 6
GUI Builder
GUI Builder
The NetBeans GUI Builder is a tool for designing GUIs (graphical user interfaces) visually. As you
create and modify your GUI, the IDE automatically generates the Java code to implement the
interface.
Tip 49: Design GridBag Layouts Easily
Not only is the NetBeans GUI Builder Matisse the ideal choice for creating GUIs with the new
dynamic FreeDesign, but it also assists you with another common layout, GridBag.
Create a new project and use File > New File to create a new JFrame. When the JFrame comes up in the
GUI Builder’s Design view, right-click and select Set Layout > GridBagLayout, as shown in Figure 41.
75
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 41:
Switching to a
different layout
manager
SECTION 6
GUI Builder
Press Ctrl-Shift-8 (Mac: Command-Shift-8) to open the Component Palette; select GUI components
and drop them onto the JFrame. In this example, I added a JButton, a JLabel, and a JTextField. Now
right-click the JFrame and select Customize Layout from the context menu (shown in Figure 42).
76
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
The GridBag Customizer opens, as shown in Figure 43. With the GridBag Customizer you get
immediate visual feedback while you edit the properties of a GridBag layout. You can rearrange
components by dragging them with the mouse to another field in the grid. You can assign values
to insets, padding, weights, grid size, and anchoring for each component.
Whenever you create a GUI with rows and columns that fits the grid scheme, the GridBag
Customizer is a good choice.
FIGURE 42:
Customizing the
GridBag layout
SECTION 6
GUI Builder
Tip Source
http://ui.netbeans.org/docs/ui/customizer/
77
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 43:
The GridBag
Customizer dialog
SECTION 6
GUI Builder
Tip 50: Add Multiple GUI Components to the Canvas
When creating GUIs in the editor’s Design view, you often find yourself going to and from the
Palette to select the same kind of element again and again. There is a faster way of creating a set of
GUI components of the same type.
1. Use File > New File to create a new JFrame and open it in the GUI Builder.
2. Click in the Palette to select the GUI component—for example, a button.
3. Move the mouse over to the frame. An instance of the component follows the cursor.
4. Hold down the Shift key, and click to place the component. The GUI Builder will remember
the presently selected component.
5. Shift-Click once for each component of the same type you want to add (see Figure 44).
78
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 44:
Adding a row of
buttons to a form
SECTION 6
GUI Builder
6. Release the Shift key right before you place the last component.
Tip Source
http://blogs.sun.com/roumen/entry/netbeans_quick_tip_15_adding
Tip 51: Create Tabbed Panes
The NetBeans GUI Builder can assist you in creating complex GUIs such as tabbed panes easily and
quickly. Use File > New File to create a new JFrame, and open the Palette.
1. Drag a JTabbedPane from the Component Palette onto the Designer (see Figure 45).
79
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 45:
Adding a
JTabbedPane to a
form
2. Drag a JPanel onto the JTabbedPane. This is how you add the first tab (see Figure 46).
3. Drag another JPanel onto the existing tab’s label until you see the orange dashed outline
(see Figure 47).

Get Checkered Flag Projects: 10 Rules for Creating and Managing Projects That Win! Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.