Class ModalDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class ModalDialog extends JDialog
Class for modal dialogs with ok and cancel buttons.

This is a try for a better design approach to modal dialogs than offered in the java development kit:
The service of a modal dialog that offers cancel and ok is separated from the retrieval of data of such a dialog. The component that queries the data from this service is freely choosable. It may be passed to the contstructor and will be returned from showDialog(). The client code then is sure that the modal dialog has been confirmed by the human interactor and may query this component for input: it knows about the component that was used to query inputs.

However for easy String prompts you should prefer: JOptionPane.showInputDialog(Object).

Version:
$Revision: 1.14 $
Author:
Achim Westermann
See Also:
  • Field Details

    • m_ok

      protected boolean m_ok
      Stores whether OK or Cancel was pressed.
  • Constructor Details

    • ModalDialog

      public ModalDialog(Component dialogParent, String title, JComponent controlComponent)
      Creates a modal dialog.

      Parameters:
      dialogParent - the parent Component for the dialog.
      title - the String containing the dialog's title.
      controlComponent - the UI component that is additionally shown and returned from showDialog().
  • Method Details

    • isOk

      public final boolean isOk()
      Returns whether OK was pressed or not.

      Returns:
      whether OK was pressed or not.
    • showDialog

      public JComponent showDialog() throws HeadlessException
      Shows a modal dialog and blocks until the dialog is hidden.

      If the user presses the "OK" button, then this method hides/disposes the dialog and returns the custom component that queries for user input. If the user presses the "Cancel" button or closes the dialog without pressing "OK", then this method hides/disposes the dialog and returns null.

      Returns:
      the custom component given to the constructor with it's new settings or null if the user opted out.
      Throws:
      HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
      See Also: