Java Reference
In-Depth Information
JDialog(Frame parent) : Creates a modeless dialog with an empty title bar.
JDialog(Frame parent, String title) : Creates a modeless dialog with the title string in
the title bar.
JDialog(Frame parent, boolean modal) : Creates a dialog with an empty title bar. If modal is
true then the dialog is modal.
JDialog(Frame parent, String title, boolean modal) : Creates a dialog with the title
string in the title bar. If modal is true then the dialog is modal.
JDialog(Frame parent, String title, boolean modal, GraphicsConfiguration gc) :
Creates a dialog with the title string in the title bar. If modal is true then the dialog is modal.
The gc parameter describes the characteristics (resolution, color depth, and so on) of the device
on which the dialog is to be displayed.
Because the first parameter to these constructors is of type Frame , you can supply a reference of type
Frame or of type JFrame to identify the parent window. There are a further five constructors for creating
JDialog objects with a Dialog or JDialog object as the parent. The only difference between these and the
ones in the preceding list is that the type of the first parameter is Dialog rather than Frame . Any of these
constructors can throw an exception of type HeadlessException if the system on which the code is execut-
ing does not have a display attached.
After you've created a JDialog object, you can switch the dialog window it produces between modal
and modeless by calling the setModal() method for the object. With a true argument to the method the
dialog is modal, and false makes it modeless. The isModal() method for a JDialog object returns true if
it represents a modal dialog and false otherwise.
All JDialog objects are initially invisible, so to display them you must call the setVisible() method
for the JDialog object with the argument true . This method is inherited from the Component class via the
Container and Window classes. If you call setVisible() with the argument false , the dialog window is
removed from the screen. After you've displayed a modal dialog window, the user can't interact with any of
the other application windows until you call setVisible() for the dialog object with the argument false ,
so you typically do this in the event handler that is called to close the dialog. Note that the setVisible()
method affects only the visibility of the dialog. You still have a perfectly good JDialog object. When you
want to display the dialog again, you just call its setVisible( ) method with the argument true . Of course,
if you call dispose() for the JDialog object, or set the default close operation to DISPOSE_ON_CLOSE , then
you aren't able to use the JDialog object again.
You can set or change the title bar for a dialog by passing a String object to the setTitle() method
for the JDialog object. The getTitle() method for a dialog returns a reference to a String object that
contains the title bar string.
Dialog windows are resizable by default, so you can change the size of a dialog window by dragging its
boundaries. If you don't want to allow a dialog window to be resized, you can inhibit this by calling the
setResizable() method for the JDialog object with the argument as false . An argument value of true
enables the resizing capability.
A Simple Modal Dialog
The simplest kind of dialog just displays some information. You could see how this works by adding a Help
menu with an About menu item and then displaying an About dialog to provide information about the ap-
plication.
Search WWH ::




Custom Search