
component is centered. Other values position the component appropriately
between these positions. When a
Box needs to position a component vertically in
arow, it uses the component’s
alignmentY pr operty to place the component in the
vertical plane in an analogous way.
Simple Dialogs
GUIs often use dialog boxes to handle simple interactions with the user.
javax.swing.JOptionPane is a Swing component that is designed to serve as a
highly configurable body of a dialog box. Instead of using the
JOptionPane
dir ectly, however, most Swing programs use one or more of the many static meth-
ods defined by
JOptionPane. These methods make it quite easy to implement sim-
ple dialog-based interactions.
If you take a look at the API for
JOptionPane, you’ll see that the class defines a
gr oup of static methods whose names begin with
show and another whose names
begin with
showInternal. The show methods display simple dialog boxes within
JDialog windows, while the showInternal methods display the same dialog boxes
inside
JInternalFrame windows. These static methods are further broken down by
the type of dialog they display. There are several versions of
showMessageDia-
log(), showConfirmDialog(), and showInputDialog(),aswell as showInternal
versions of the same methods. We’ll consider these three types of dialogs—mes-
sage, confirm, and input—in the sections that follow.
Message Dialogs
Message dialogs are used to display important ...