Java Reference
In-Depth Information
Figure 8-30. The client application's dialog box for entering the database location
Figure 8-31. The JPanel for getting common parameters in both the client and the server
application
In Listing 8-28 we will see that the constructor for the common frame will change which
options are displayed, and what tooltip text is displayed, depending on a parameter in the
constructor. This allows us to use the same frame for stand-alone client, networked client,
and server applications.
For the main client GUI, we used the simple graphical layout managers: BorderLayout and
FlowLayout . These layout managers will serve in most cases. However, in some circumstances
you may find that you want to lay out a panel in some form that cannot be readily achieved
using these simple layout managers. The common frame is one such case—we want to have
up to four rows of components, but each component has a label that we want to align verti-
cally on its right edge.
In this section we introduce one of the most powerful layout managers—the
GridBagLayout . We deliberately delayed introducing this layout manager until now, as it is
more complicated to use than the other layout managers.
Tip Although this layout manager is very powerful, and works well in the Denny's DVD example applica-
tion, you may find that you do not need to use this layout manager in your application. We recommend that
you use the simplest solution that works for you—you will not get extra marks for proving that you can use
all the layout managers.
The GridBagLayout
Java has two grid-based layout managers: the GridLayout and the GridBagLayout manager.
The GridLayout is the simpler of the two; however, it forces all cells in the grid to be the
same size, as shown in Figure 8-32. The program that produced this is shown in Listing 8-25.
Search WWH ::




Custom Search