Chapter 6. Building Java Graphical User Interfaces


  • Using Different Layout Managers

  • Placing and Aligning a Component in a Form

  • Setting Component Size and Resizability

  • Setting Component Alignment

  • Specifying Component Behavior and Appearance

  • Generating Event Listening and Handling Methods

  • Customizing Generated Code

  • Previewing a Form

  • Using Custom Beans in the Form Editor

  • Deploying GUI Applications Developed with Matisse

ONE OF THE AREAS IN WHICH NETBEANS IDE PROVIDES THE MOST INNOVATIVE SUPPORT is for creating Java clients using Java Foundation Classes (JFC or "Swing") and AWT packages. In addition to support for building applications on top of the NetBeans Platform, NetBeans IDE also provides cutting-edge tools to design individual forms, components, and dialogs.

In the 5.0 release, NetBeans IDE revolutionized the approach to GUI layout management by introducing Project Matisse the combination of a new layout manager called GroupLayout and a visual interface used to design forms with this layout manager.

The Matisse approach arranges components using aligning and relative proximity rather than nested containers and absolute X and Y coordinates. Components are anchored to the sides of a container and to other components. You can set two components to, for example, be aligned along the baseline or along the left or right edge. When the the size of components changes, either when the form is localized or when the user resizes the form, all of the components remain aligned correctly.

Another advantage of the Matisse approach is that the default spacing between components is defined by the look and feel of the program rather than in absolute pixels. This means that your form will always look like a native application on an operating system.

NetBeans IDE includes a number of tools for working with Java GUI forms, including:

  • Form Editor. Provides both Design and Source views for you to create visual components. The Design view is an area where you can drag, drop, and rearrange the visual components that make up the user interface of the client you are building. The Source view contains the generated source code for the class you are designing and also allows you to enter your own code for the class.

  • Inspector window. Provides a tree view of all of the components in the form, whether visual (such as menus, text fields, labels, and buttons) or nonvisual (such as button groups and data sources). This window appears in the same space as the Navigator window.

  • Palette window. Provides a list of components that you can drag and drop onto your form. You can choose from Swing and AWT components or add your own custom beans.

  • Properties window. Contains a list of editable properties for the selected component and access to special property editors for the more complex properties.

  • Connection wizard. Helps you create event listener and event handler code that links two components.

  • Form Tester. Quickly displays a runtime view of the form under construction, allowing checks of resizing and other behavior.

  • Palette Manager. Enables you to add custom components to the Palette window. Choose Tools | Palette Manager | Swing/AWT Components to open this window.

The Form Editor, Inspector window, Palette window, and Properties window are shown in Figure 6-1. You can access the Connection wizard and Form Tester from buttons in the toolbar area of the Form Editor.

Figure 6-1. Form Editor windows, including the Inspector, Form Editor (Design View), Palette window, and Properties window


This section does not provide a complete guide to developing visual applications with Swing in NetBeans IDE; a whole book could be devoted to that. Instead, it focuses on a few of the unique but somewhat tricky features of Swing and the IDE that assist in the designing of visual applications.



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