Class OptionDialog

    • Constructor Detail

      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               int messageType,
                               javax.swing.Icon icon)
        Construct a simple informational dialog with a single OK button.
        Parameters:
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        messageType - used to specify a default icon
        • ERROR_MESSAGE
        • INFORMATION_MESSAGE
        • WARNING_MESSAGE
        • QUESTION_MESSAGE
        • PLAIN_MESSAGE
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               java.lang.String option1,
                               java.lang.String option2,
                               int messageType,
                               javax.swing.Icon icon,
                               boolean addCancel)
        Construct a simple two-option dialog.
        Parameters:
        title - the String to place in the dialog's title area.
        message - the message string explaining the user's option.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        addCancel - true means add a Cancel button
      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               java.lang.String option1,
                               java.lang.String option2,
                               int messageType,
                               javax.swing.Icon icon,
                               boolean addCancel,
                               java.lang.String defaultButtonName)
        Construct a simple two-option dialog.
        Parameters:
        title - the String to place in the dialog's title area.
        message - the message string explaining the user's option.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        addCancel - true means add a Cancel button
        defaultButtonName - The default button name
      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               java.lang.String option1,
                               int messageType,
                               javax.swing.Icon icon)
        Construct a simple one-option dialog with a Cancel button.
        Parameters:
        title - the String to place in the dialog's title area.
        message - the message string explaining the user's option.
        option1 - The text to place on the first option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               java.lang.String option1,
                               int messageType,
                               javax.swing.Icon icon,
                               java.lang.String defaultButtonName)
        Construct a simple one-option dialog with a Cancel button.
        Parameters:
        title - the String to place in the dialog's title area.
        message - the message string explaining the user's option.
        option1 - The text to place on the first option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        defaultButtonName - the name of the button to be made the default.
      • OptionDialog

        protected OptionDialog​(java.lang.String title,
                               java.lang.String message,
                               java.lang.String option1,
                               java.lang.String option2,
                               java.lang.String option3,
                               int messageType,
                               javax.swing.Icon icon,
                               boolean addCancel)
    • Method Detail

      • createTextPanel

        protected javax.swing.JPanel createTextPanel​(java.lang.String message)
      • getMessage

        public java.lang.String getMessage()
        Returns the dialog's message to the user
        Returns:
        the message
      • show

        public int show()
      • show

        public int show​(java.awt.Component parent)
      • createBuilder

        public static OptionDialogBuilder createBuilder​(java.lang.String title,
                                                        java.lang.String message)
        A convenience method to create a OptionDialogBuilder
        Parameters:
        title - the dialog title
        message - the dialog message
        Returns:
        the builder
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialogWithCancelAsDefaultButton

        public static int showOptionDialogWithCancelAsDefaultButton​(java.awt.Component parent,
                                                                    java.lang.String title,
                                                                    java.lang.String message,
                                                                    java.lang.String option1)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.

        The dialog shown by this method will have the cancel button set as the default button so that an Enter key press will trigger a cancel action.

        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialogWithCancelAsDefaultButton

        public static int showOptionDialogWithCancelAsDefaultButton​(java.awt.Component parent,
                                                                    java.lang.String title,
                                                                    java.lang.String message,
                                                                    java.lang.String option1,
                                                                    int messageType)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.

        The dialog shown by this method will have the cancel button set as the default button so that an Enter key press will trigger a cancel action.

        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           int messageType)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           int messageType,
                                           java.lang.String defaultButtonName)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        defaultButtonName - the name of the button to be the default. Null will make the first button the default
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           javax.swing.Icon icon)
        Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the option button.
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        Returns:
        The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           java.lang.String option2,
                                           java.lang.String option3,
                                           int messageType)
        Static helper method to easily display an three-option dialog. The dialog will remain until the user presses the Option1, Option2, Option3 or Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used.
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        option3 - The text to place on the third option button.
        messageType - The type of message to display
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option and so on. 0 is returned if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           java.lang.String option2)
        Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.\
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           java.lang.String option2,
                                           int messageType)
        Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showOptionDialog

        public static int showOptionDialog​(java.awt.Component parent,
                                           java.lang.String title,
                                           java.lang.String message,
                                           java.lang.String option1,
                                           java.lang.String option2,
                                           javax.swing.Icon icon)
        Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showOptionNoCancelDialog

        public static int showOptionNoCancelDialog​(java.awt.Component parent,
                                                   java.lang.String title,
                                                   java.lang.String message,
                                                   java.lang.String option1,
                                                   java.lang.String option2,
                                                   int messageType)
        Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showOptionNoCancelDialog

        public static int showOptionNoCancelDialog​(java.awt.Component parent,
                                                   java.lang.String title,
                                                   java.lang.String message,
                                                   java.lang.String option1,
                                                   java.lang.String option2,
                                                   javax.swing.Icon icon)
        Static helper method to easily display an two-option dialog with no Cancel button. The dialog will remain until the user presses the Option1 or Option 2 button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        icon - allows the user to specify the icon to be used. If non-null, this will override the messageType.
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showOptionNoCancelDialog

        public static int showOptionNoCancelDialog​(java.awt.Component parent,
                                                   java.lang.String title,
                                                   java.lang.String message,
                                                   java.lang.String option1,
                                                   java.lang.String option2,
                                                   java.lang.String option3,
                                                   int messageType)
        Static helper method to easily display an three-option dialog with no Cancel button. The dialog will remain until the user presses the Option1, Option 2, or Option 3 button.
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        option1 - The text to place on the first option button.
        option2 - The text to place on the second option button.
        option3 - The text to place on the third option button.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
      • showYesNoDialog

        public static int showYesNoDialog​(java.awt.Component parent,
                                          java.lang.String title,
                                          java.lang.String message)
        Dialog with only YES/NO options, no CANCEL
        Parameters:
        parent - The parent dialog or frame of this dialog. (Can be null)
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        Returns:
        The options selected by the user:
                          0 is returned if the operation is cancelled
                          1 for Yes
                          2 for No
         
      • showYesNoDialogWithNoAsDefaultButton

        public static int showYesNoDialogWithNoAsDefaultButton​(java.awt.Component parent,
                                                               java.lang.String title,
                                                               java.lang.String message)
        Dialog with only YES/NO options, no CANCEL

        The dialog shown by this method will have the No button set as the default button so that an Enter key press will trigger a No action.

        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        Returns:
        The options selected by the user:
                          1 for Yes
                          2 for No
         
      • showYesNoCancelDialog

        public static int showYesNoCancelDialog​(java.awt.Component parent,
                                                java.lang.String title,
                                                java.lang.String message)
        Dialog with only YES/NO options, no CANCEL
        Parameters:
        parent - The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behavior
        title - The String to be placed in the dialogs title area.
        message - The information message to be displayed in the dialog.
        Returns:
        The options selected by the user:
                          0 is returned if the operation is cancelled
                          1 for the first option
                          2 for the second option
         
      • showInputSingleLineDialog

        public static java.lang.String showInputSingleLineDialog​(java.awt.Component parent,
                                                                 java.lang.String title,
                                                                 java.lang.String label,
                                                                 java.lang.String initialValue)
        Displays a dialog for the user to enter a string value on a single line.
        Parameters:
        parent - the component to parent this dialog to
        title - the title to display on the input dialog
        label - the label to display in front of the text field
        initialValue - an optional value to set in the text field, can be null
        Returns:
        the string entered OR null if the dialog was canceled.
      • showInputMultilineDialog

        public static java.lang.String showInputMultilineDialog​(java.awt.Component parent,
                                                                java.lang.String title,
                                                                java.lang.String label,
                                                                java.lang.String initialValue)
        Displays a dialog for the user to enter a multi-line string value.
        Parameters:
        parent - the component to parent this dialog to
        title - the title to display on the input dialog
        label - the label to display in front of the text area
        initialValue - an optional value that will be set in the text area, can be null
        Returns:
        the string entered OR null if the dialog was canceled.
      • showInputChoiceDialog

        public static java.lang.String showInputChoiceDialog​(java.awt.Component parent,
                                                             java.lang.String title,
                                                             java.lang.String label,
                                                             java.lang.String[] selectableValues,
                                                             java.lang.String initialValue,
                                                             int messageType)
        Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings.
        Parameters:
        parent - the component to parent this dialog to
        title - the title to display on the input dialog
        label - the label to display in front of the combo box
        selectableValues - an array of string to choose from
        initialValue - an optional value to set the combo box to, can be null in which the combo box will have the first item from the selectable values.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        the string entered or chosen OR null if the dialog was canceled.
      • showEditableInputChoiceDialog

        public static java.lang.String showEditableInputChoiceDialog​(java.awt.Component parent,
                                                                     java.lang.String title,
                                                                     java.lang.String label,
                                                                     java.lang.String[] selectableValues,
                                                                     java.lang.String initialValue,
                                                                     int messageType)
        Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings. The list of possible values is editable such that the user can enter their own value by typing text.
        Parameters:
        parent - the component to parent this dialog to
        title - the title to display on the input dialog
        label - the label to display in front of the combo box
        selectableValues - an array of string to choose from
        initialValue - an optional value to set the combo box to, can be null in which the combo box will have the first item from the selectable values.
        messageType - used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)
        Returns:
        the string entered or chosen OR null if the dialog was canceled.
      • getResult

        public final int getResult()
        Returns which option was selected: CANCEL_OPTION if the operation was cancelled; OPTION_ONE if Option 1 was selected; OPTION_TWO if Option 2 was selected.
        Returns:
        selected option; returns CANCEL_OPTION for informational dialogs
      • getIconForMessageType

        public static javax.swing.Icon getIconForMessageType​(int messageType)
        Returns the Icon to use for the given message type.
        Parameters:
        messageType - the type of message being displayed.
        Returns:
        the appropriate Icon.