Dialog : Java Glossary
home D words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
Dialog
Dialogs are a type of Window that pop up over a parent Frame, usually to ask the user to confirm something or display an About box. Dialogs can be modal or non-modal. Modal dialogs monopolise the user’s attention, preventing him from clicking anywhere but in the dialog box. Early versions of Dialog were quite buggy.

JDialog is the Swing equivalent of Dialog.

Gotchas Learning More
Sample Code Links

Gotchas

Dialog is primitive. There is no built-in mechanism to get data back to the caller. You have to borrow code from a Component like Choice to have the caller register himself as an EventListener to events your Dialog broadcasts and offer public methods for the caller to interrogate. It is much like writing a new sort of Component.

Dialog constructors want a Frame as parent. Unfortunately, Applets are effectively Panels, not Frames. To embed a Dialog in an Applet, you must chase the Component. getParent chain until you find an instanceof Frame. Alternatively, you can pop up a new Frame for the Dialog to live in.

Modal Dialogs are most peculiar. They don’t immediately return to the caller when you call setVisible( true) followed by a return. They only return after the Dialog has disposed. Check out ColorChooser in FontShowerAwt for how you pass data gleaned from the user back to the code that invoked the Dialog.

In a nutshell, you first construct the modal Dialog, but don’t call setVisible( true ). Then you call a Dialog. query method that calls setVisible( true ) then returns the desired variables. Setvisible( true ) magically puts the query method on ice while the user interacts and finally hits OK or Cancel which triggers an ActionListener to call dispose. At that point the query method magically resumes executing, and can pick out whatever data it wants that the GUI interactions put into the Dialog fields. It can then bundle them into an Object or array to return to the caller.

If Dialogs fail to paint anything, it could be because you forgot to do a setSize, validate(), or setVisible( true ). Dialog.setBackground does not work.

Sample Code

Learning More

Sun’s Javadoc on the Dialog class : available:

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] The information on this page is for non-military use only.
You are visitor number 13,049. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/dialog.html J:\mindprod\jgloss\dialog.html