GUI Basics

For some very basic information about GUI's and why you should use constraint-based layouts and a GUI builder, see George's powerpoint.

NetBeans GUI's

You can find a basic tutorial on the NetBeans GUI builder on the actual NetBeans site. Here are a few more tips that I found that were not in the tutorial.



When you are typing text for JLabels, JButtons, etc. you can actually use HTML within the text. Say you have a label that you want to take up two lines, simply enclose the text in <html></html> tags, and use a <br> where needed. CAUTION: Turning text into HTML will cause lines to wrap when your form is resized.

Add Images


You can add images to many elements in the GUI builder (JLabels, JButtons, ...). In the Properties box, choose "Icon." A window will pop up where you can choose the icon you would like. If you choose "File" and choose the images from your hard drive, then nobody else in the group will be able to see the images when they open your project from SVN. To fix this, you need to include images from the Classpath. When all of your images are completed, save them all in a file (icons.jar). Place this Jar file within your class folder, and then point your paths to the images within the Jar.

Center Horizontally

Customize the Layout

By default, the layout for forms can not center horizontally. You must anchor everything either left or right, and either top or bottom. To get around this, we'll use another layout. If you only want one row of buttons to center, create a JPanel where that row will go. Right click on the JPanel and choose "Set Layout" > "GridBagLayout." Now, when you add items into the JPanel, they will all go side by side, centered horizontally. If you'd like two rows of buttons, you can either add another JPanel, or edit the GridBagLayout in the current panel. To do this, right click the panel and choose "Customize Layout." This will bring up the customizer where you can drag items around and line them up they way you'd like.

Layout Customizer

Tabbed Panes

Tabbed Panes

This is the least intuitive thing in the GUI builder. To create a tabbed pane, you must drag a JTabbedPane onto you form, and then resize it to the size you want. Now, in order to actually get tabs to appear, you must add JPanel into the JTabbedPane. Click to add JPanel, and then hover over the JTabbedPane until you get a dashed orange box inside of the tabbed pane. If you add the panel here, it will appear inside the pane and have its own tab. To add more, repeat this process making sure that you have a dashed orange line before adding the next JPanel.