Java Reference
In-Depth Information
Modal and Non-modal Dialogs
There are two different kinds of dialog that you can create, and they have distinct operating
characteristics. You have a choice of creating either a modal dialog or a non-modal dialog . When you
display a modal dialog - by selecting a menu item or clicking a button, it inhibits the operation of any
other windows in the application until you close the dialog. The dialog opposite that displays a message
is a modal dialog. The dialog window retains the focus as long as it is displayed and operation of the
application cannot continue until you click the OK button. Modal dialogs that manage input will
normally have at least two buttons, an OK button that you use to accept whatever input has been
entered and then close the dialog, and a Cancel button to just close the dialog and abort the entry of the
data. Dialogs that manage input are almost always modal dialogs, simply because you won't generally
want to allow other interactions to be triggered until your user's input is complete.
A non-modal dialog can be left on the screen for as long as you want, since it doesn't block interaction
with other windows in the application. You can also switch the focus back and forth between using a
non-modal dialog and using any other application windows that are on the screen.
Whether you create a modal or a non-modal dialog is determined either by an argument to a dialog
class constructor, or by which constructor you choose, since some of them create non-modal dialogs by
default. The default, no-argument JDialog constructor creates a non-modal dialog with an empty title
bar. Since you have no provision for specifying a parent window for the dialog, a shared hidden frame
will be used as the parent in this case. You have a choice of five constructors for creating a JDialog
object where the parent can be a window of type Frame or JFrame :
Constructor
Description
title bar
parent
window
Mode
JDialog(Frame parent)
(empty)
parent
non-modal
JDialog(Frame parent,
String title)
title
parent
non-modal
JDialog(Frame parent,
boolean modal)
(empty)
parent
modal (when modal arg
is true )
non-modal (when
modal arg is false )
JDialog(Frame parent,
String title,
boolean modal)
title
parent
modal (when modal arg
is true )
non-modal (when
modal arg is false )
JDialog(Frame parent,
String title,
boolean modal,
GraphicsConfiguration gc)
title
parent
modal (when modal arg
is true )
non-modal (when
modal arg is false )
Search WWH ::




Custom Search