Package jmri.util.swing
Class JmriJOptionPane
java.lang.Object
jmri.util.swing.JmriJOptionPane
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final Stringstatic final intstatic final intstatic final intstatic final intstatic final Objectstatic final intstatic final intstatic final intstatic final intstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WindowfindWindowForObject(Object object) Find the parent Window, normally from a java.awt.Component .static intshowConfirmDialog(Component parentComponent, Object message, String title, int optionType) Displays a confirmation dialog with a message and title.static intshowConfirmDialog(Component parentComponent, Object message, 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 ObjectshowInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) Displays an input dialog.static ObjectshowInputDialog(Component parentComponent, String message, Object initialSelectionValue) Displays an Object input dialog.static StringshowInputDialog(Component parentComponent, String message, String initialSelectionValue) Displays a String input dialog.static StringshowInputDialog(Component parentComponent, String message, String title, int messageType) Displays a String input dialog.static voidshowMessageDialog(Component parentComponent, Object message) Displays an informational message dialog with an OK button.static voidshowMessageDialog(Component parentComponent, Object message, String title, int messageType) Displays a message dialog with an OK button.static voidshowMessageDialogNonModal(Component parentComponent, Object message, String title, int messageType, Runnable callback) Displays a Non-Modal message dialog with an OK button.static intshowOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) Displays a custom option dialog.
-
Field Details
-
CANCEL_OPTION
- See Also:
-
OK_OPTION
- See Also:
-
OK_CANCEL_OPTION
- See Also:
-
YES_OPTION
- See Also:
-
YES_NO_OPTION
- See Also:
-
YES_NO_CANCEL_OPTION
- See Also:
-
NO_OPTION
- See Also:
-
CLOSED_OPTION
- See Also:
-
DEFAULT_OPTION
- See Also:
-
UNINITIALIZED_VALUE
-
ERROR_MESSAGE
- See Also:
-
INFORMATION_MESSAGE
- See Also:
-
PLAIN_MESSAGE
- See Also:
-
QUESTION_MESSAGE
- See Also:
-
WARNING_MESSAGE
- See Also:
-
YES_STRING
-
NO_STRING
-
-
Constructor Details
-
JmriJOptionPane
protected JmriJOptionPane()
-
-
Method Details
-
showMessageDialog
public static void showMessageDialog(@CheckForNull Component parentComponent, Object message) throws 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:
HeadlessException- if the current environment is headless (no GUI available).
-
showMessageDialog
public static void showMessageDialog(@CheckForNull Component parentComponent, Object message, 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:
HeadlessException- if the current environment is headless (no GUI available).
-
showMessageDialogNonModal
public static void showMessageDialogNonModal(@CheckForNull Component parentComponent, Object message, String title, int messageType, @CheckForNull 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:
HeadlessException- if the current environment is headless (no GUI available).
-
showConfirmDialog
public static int showConfirmDialog(@CheckForNull Component parentComponent, Object message, String title, int optionType) throws 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, orCLOSED_OPTION. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
showConfirmDialog
public static int showConfirmDialog(@CheckForNull Component parentComponent, Object message, String title, int optionType, int messageType) throws 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, orCLOSED_OPTION. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
showOptionDialog
public static int showOptionDialog(@CheckForNull Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws 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_OPTIONif the dialog is closed. - Throws:
HeadlessException- If the current environment is headless (no GUI available).
-
showInputDialog
@CheckForNull public static String showInputDialog(@CheckForNull Component parentComponent, String message, 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
nullif the dialog is closed or the input value is uninitialized. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
showInputDialog
@CheckForNull public static String showInputDialog(@CheckForNull Component parentComponent, String message, 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
nullif the dialog is closed or the input value is uninitialized. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
showInputDialog
@CheckForNull public static Object showInputDialog(@CheckForNull Component parentComponent, String message, 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
nullif the dialog is closed or the input value is uninitialized. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
showInputDialog
@CheckForNull public static Object showInputDialog(@CheckForNull Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) throws 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
nullif the dialog is closed or the input value is uninitialized. - Throws:
HeadlessException- if the current environment is headless (no GUI available).
-
findWindowForObject
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.
-