Class JmriJOptionPane


  • public class JmriJOptionPane
    extends java.lang.Object
    JmriJOptionPane provides a set of static methods to display Dialogs and retrieve user input. These can directly replace the javax.swing.JOptionPane static methods.

    If the parentComponent is null, all Dialogs created will be Modal. These will block the whole JVM UI until they are closed. These may appear behind Window frames with Always On Top enabled and may not be accessible. These Dialogs are positioned in the centre of the screen.

    If a parentComponent is provided, the Dialogs will be created Modal to ( will block ) the parent Window Frame, other Frames are not blocked. These Dialogs will appear in the centre of the parent Frame.

    Since:
    5.5.4
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JmriJOptionPane()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Window findWindowForObject​(java.lang.Object object)
      Find the parent Window, normally from a java.awt.Component .
      static int showConfirmDialog​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int optionType)
      Displays a confirmation dialog with a message and title.
      static int showConfirmDialog​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int optionType, int messageType)
      Displays a confirmation dialog with a message and title.The dialog includes options for the user to confirm or cancel an action.
      static java.lang.Object showInputDialog​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int messageType, javax.swing.Icon icon, java.lang.Object[] selectionValues, java.lang.Object initialSelectionValue)
      Displays an input dialog.
      static java.lang.Object showInputDialog​(java.awt.Component parentComponent, java.lang.String message, java.lang.Object initialSelectionValue)
      Displays an Object input dialog.
      static java.lang.String showInputDialog​(java.awt.Component parentComponent, java.lang.String message, java.lang.String initialSelectionValue)
      Displays a String input dialog.
      static java.lang.String showInputDialog​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, int messageType)
      Displays a String input dialog.
      static void showMessageDialog​(java.awt.Component parentComponent, java.lang.Object message)
      Displays an informational message dialog with an OK button.
      static void showMessageDialog​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int messageType)
      Displays a message dialog with an OK button.
      static void showMessageDialogNonModal​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int messageType, java.lang.Runnable callback)
      Displays a Non-Modal message dialog with an OK button.
      static int showOptionDialog​(java.awt.Component parentComponent, java.lang.Object message, java.lang.String title, int optionType, int messageType, javax.swing.Icon icon, java.lang.Object[] options, java.lang.Object initialValue)
      Displays a custom option dialog.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • showMessageDialog

        public static void showMessageDialog​(@CheckForNull
                                             java.awt.Component parentComponent,
                                             java.lang.Object message)
                                      throws java.awt.HeadlessException
        Displays an informational message dialog with an OK button.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showMessageDialog

        public static void showMessageDialog​(@CheckForNull
                                             java.awt.Component parentComponent,
                                             java.lang.Object message,
                                             java.lang.String title,
                                             int messageType)
        Displays a message dialog with an OK button.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        messageType - The type of message to be displayed (e.g., WARNING_MESSAGE).
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showMessageDialogNonModal

        public static void showMessageDialogNonModal​(@CheckForNull
                                                     java.awt.Component parentComponent,
                                                     java.lang.Object message,
                                                     java.lang.String title,
                                                     int messageType,
                                                     @CheckForNull
                                                     java.lang.Runnable callback)
        Displays a Non-Modal message dialog with an OK button.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        messageType - The type of message to be displayed (e.g., WARNING_MESSAGE).
        callback - Code to run when the Dialog is closed. Can be null.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showConfirmDialog

        public static int showConfirmDialog​(@CheckForNull
                                            java.awt.Component parentComponent,
                                            java.lang.Object message,
                                            java.lang.String title,
                                            int optionType)
                                     throws java.awt.HeadlessException
        Displays a confirmation dialog with a message and title. The dialog includes options for the user to confirm or cancel an action.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        optionType - The type of options to be displayed (e.g., YES_NO_OPTION, OK_CANCEL_OPTION).
        Returns:
        An integer representing the user's choice: YES_OPTION, NO_OPTION, CANCEL_OPTION, or CLOSED_OPTION.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showConfirmDialog

        public static int showConfirmDialog​(@CheckForNull
                                            java.awt.Component parentComponent,
                                            java.lang.Object message,
                                            java.lang.String title,
                                            int optionType,
                                            int messageType)
                                     throws java.awt.HeadlessException
        Displays a confirmation dialog with a message and title.The dialog includes options for the user to confirm or cancel an action.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        optionType - The type of options to be displayed (e.g., YES_NO_OPTION, OK_CANCEL_OPTION).
        messageType - The type of message to be displayed (e.g., ERROR_MESSAGE).
        Returns:
        An integer representing the user's choice: YES_OPTION, NO_OPTION, CANCEL_OPTION, or CLOSED_OPTION.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showOptionDialog

        public static int showOptionDialog​(@CheckForNull
                                           java.awt.Component parentComponent,
                                           java.lang.Object message,
                                           java.lang.String title,
                                           int optionType,
                                           int messageType,
                                           javax.swing.Icon icon,
                                           java.lang.Object[] options,
                                           java.lang.Object initialValue)
                                    throws java.awt.HeadlessException
        Displays a custom option dialog.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        optionType - The type of options to be displayed (e.g., YES_NO_OPTION, OK_CANCEL_OPTION).
        messageType - The type of message to be displayed (e.g., INFORMATION_MESSAGE, WARNING_MESSAGE).
        icon - The icon to be displayed in the dialog.
        options - An array of objects representing the options available to the user.
        initialValue - The initial value selected in the dialog.
        Returns:
        An integer representing the index of the selected option, or CLOSED_OPTION if the dialog is closed.
        Throws:
        java.awt.HeadlessException - If the current environment is headless (no GUI available).
      • showInputDialog

        @CheckForNull
        public static java.lang.String showInputDialog​(@CheckForNull
                                                       java.awt.Component parentComponent,
                                                       java.lang.String message,
                                                       java.lang.String initialSelectionValue)
        Displays a String input dialog.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        initialSelectionValue - The initial value pre-selected in the input dialog.
        Returns:
        The user's String input value, or null if the dialog is closed or the input value is uninitialized.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showInputDialog

        @CheckForNull
        public static java.lang.String showInputDialog​(@CheckForNull
                                                       java.awt.Component parentComponent,
                                                       java.lang.String message,
                                                       java.lang.String title,
                                                       int messageType)
        Displays a String input dialog.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The dialog Title.
        messageType - The type of message to be displayed (e.g., QUESTION_MESSAGE ).
        Returns:
        The user's String input value, or null if the dialog is closed or the input value is uninitialized.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showInputDialog

        @CheckForNull
        public static java.lang.Object showInputDialog​(@CheckForNull
                                                       java.awt.Component parentComponent,
                                                       java.lang.String message,
                                                       java.lang.Object initialSelectionValue)
        Displays an Object input dialog.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        initialSelectionValue - The initial value pre-selected in the input dialog.
        Returns:
        The user's input value, or null if the dialog is closed or the input value is uninitialized.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • showInputDialog

        @CheckForNull
        public static java.lang.Object showInputDialog​(@CheckForNull
                                                       java.awt.Component parentComponent,
                                                       java.lang.Object message,
                                                       java.lang.String title,
                                                       int messageType,
                                                       javax.swing.Icon icon,
                                                       java.lang.Object[] selectionValues,
                                                       java.lang.Object initialSelectionValue)
                                                throws java.awt.HeadlessException
        Displays an input dialog.
        Parameters:
        parentComponent - The parent component relative to which the dialog is displayed.
        message - The message to be displayed in the dialog.
        title - The title of the dialog.
        messageType - The type of message to be displayed (e.g., INFORMATION_MESSAGE, WARNING_MESSAGE).
        icon - The icon to be displayed in the dialog.
        selectionValues - An array of objects representing the input selection values.
        initialSelectionValue - The initial value pre-selected in the input dialog.
        Returns:
        The user's input value, or null if the dialog is closed or the input value is uninitialized.
        Throws:
        java.awt.HeadlessException - if the current environment is headless (no GUI available).
      • findWindowForObject

        @CheckForNull
        public static java.awt.Window findWindowForObject​(@CheckForNull
                                                          java.lang.Object object)
        Find the parent Window, normally from a java.awt.Component .

        If the component is within a JPopupMenu, the parent Window of the Popup Menu will be returned, not the Frame of the Popup Menu itself ( which may no longer be visible ).

        Parameters:
        object - a child component of the Window.
        Returns:
        the parent Window, or null if none found.