I want to understand how java.awt.Dialog
achieves modality (blocking other windows)?
Yeah, I tried reading the code of java.awt.Dialog
, but I am kind of getting lost in it. So I want to know briefly what they do. Do they disable all events of all other windows?
Thanks Prem
The Dialog control represents a top level window with a border and a title used to take some form of input from the user. It inherits the Window class. Unlike Frame, it doesn't have maximize and minimize buttons.
There are two basic types of dialogs: modal and modeless. Modal dialogs block input to other top-level windows. Modeless dialogs allow input to other windows. An open file dialog is a good example of a modal dialog.
The showMessageDialog method creates a basic one-button dialog box. The showOptionDialog method, however, enables you to customize features like the number of buttons, the words on the buttons, and even allows you to ask for input in your dialog box. Notice that line 1 in the code above imports the Swing package.
Its system dependent. On windows the main event loop is modified. You are most of the time better off opening a dialog non-modal and lock the underlying window manually (e.g. set a glasspane to the rootpane and disable it, or block all events setting a custom focus manager).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With