Dialog : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (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 (Graphic User Interface) 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

Oracle’s Javadoc on Dialog class : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/dialog.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\dialog.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.191.192.109]
You are visitor number