|C H A P T E R 5|
A Dialog is a form that occupies a part of the screen as a top level component. By default dialogs always appear as a modal entity to the user. Modality indicates that a dialog blocks the calling thread even if the calling thread is the Event Dispatcher Thread (EDT). Dialogs allow us to prompt users for information and rely on the information being returned as a response after the dialog show method. Each Dialog has a body that is located in the center of the dialog. The Body can contain a component, so you can use your own customer component or pre‐built container.
Icons are not currently provided by default, but you can manually add them to customized dialogs. Icons can be used to indicate the alert state, similar to JDialog icons in Swing. See http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html.
The arguments to all of the show methods are standardized, though the number of arguments for each method varies. The static show methods provide support for laying out standard dialogs, providing icons, specifying the dialog title and text, and customizing the button text.
The transition installed when the dialog enters and leaves the screen. For more information see Transition.
The first method takes no arguments and produces a dialog without any commands. The only way to close such a dialog is to invoke the dispose() method on the dialog. Since the dialog is blocking, meaning once the dialog is displayed its calling thread can not proceed until it is closed, the call to dispose must be made from a different thread. To do this, schedule the call to dispose with a timer thread. Note that the timer thread must be started before the dialog is displayed. This approach is referred to as an auto-closing dialog.
The second dialog type has five parameters. The first four are the four wing insets (top, bottom, left, and right) and the fifth parameter determines whether to include the Dialog title assigned through the dialog constructor (see FIGURE 5-1).
// Call show with inset parameters dialog.show(90, 90, 10, 10, true);
The dispose methods closes the current dialog and returns to the parent form. When show() is used without arguments, one way to close the dialog is to set a timer to call dispose just before calling the show method (otherwise the dispose method is never performed).
As mentioned in Non-Static Show Methods, return value types can be either Command or a boolean value. For example, if a user has a dialog with two commands, Approve and Decline, the user clicks and the selected command is returned. For the boolean return type, a true or false value indicates whether the user clicked the OK command.