Using Different Layout Managers


By default, NetBeans IDE uses the GroupLayout layout manager for any new forms that you create. This chapter deals exclusively with building Java GUIs with Matisse, which is by far the best way to develop Java GUIs. If, however, you need or prefer to work with other standard layouts, the IDE provides full support for that as well. Actions such as placing components in a form and working with component properties work the same as when working with Matisse. Only component alignment and resizing behavior differs and is controlled by the layout manager you are using.

The IDE provides full support for all of the standard Swing layouts managers:

  • FlowLayout

  • BorderLayout

  • GridLayout

  • GridBagLayout

  • CardLayout

  • BoxLayout (note that the "struts" and "glue" normally used with BoxLayout are not provided as out-of-the-box components)

In addition, support for forms without a layout manager (NullLayout) and forms with absolutely positioned components (AbsoluteLayout) is provided. Neither of these is recommended for production use, as their behavior across platforms or when resizing is unlikely to be acceptable.

To set the layout manager for a container:

  1. Right-click a container in the Inspector window and choose the layout manager from the Set Layout menu.

  2. To set the form to use a layout manager, choose the layout manager name. To set the form to use GroupLayout (Matisse), choose Free Design.

To set the layout manager back to GroupLayout, choose Set Layout | Free Design.


Tips for GUI Editing

The most important thing to remember when you begin designing a GUI is that whenever you place a component into a form, you create spacing and alignment relationships that can be tricky to change later. You therefore should never just start throwing components into a form and then try to arrange them into the desired layout.

Instead, it is good to start out with a clear idea of how you want your form to look. Sketch the form on a piece of paper or find an example of a similar form that you want to imitate.

As you work, start in the top-left corner, fill out each row, and work your way down. Use the recommended spacing and alignment that the Form Editor suggests as much as possible to guarantee that your form will look right on all operating systems.

Of course, at some point you will have to modify existing forms. Here are a few tips that help modify your forms without tearing your hair out:

  • If you have to move components that are grouped, like a row of labels and text fields, Ctrl-click the components to select them all and move them as a unit. This helps preserve the grouping relationship between the components.

  • If you get into trouble, use the Undo command to revert to your previous state and start over. Often, trying to correct the error yourself only makes things worse.




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net