Package jmri.util.swing
Class JmriJOptionPane
- java.lang.Object
-
- jmri.util.swing.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
-
-
Field Summary
Fields Modifier and Type Field Description static int
CANCEL_OPTION
static int
CLOSED_OPTION
static int
DEFAULT_OPTION
static int
ERROR_MESSAGE
static int
INFORMATION_MESSAGE
static int
NO_OPTION
static java.lang.String
NO_STRING
static int
OK_CANCEL_OPTION
static int
OK_OPTION
static int
PLAIN_MESSAGE
static int
QUESTION_MESSAGE
static java.lang.Object
UNINITIALIZED_VALUE
static int
WARNING_MESSAGE
static int
YES_NO_CANCEL_OPTION
static int
YES_NO_OPTION
static int
YES_OPTION
static java.lang.String
YES_STRING
-
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.
-
-
-
Field Detail
-
CANCEL_OPTION
public static final int CANCEL_OPTION
- See Also:
- Constant Field Values
-
OK_OPTION
public static final int OK_OPTION
- See Also:
- Constant Field Values
-
OK_CANCEL_OPTION
public static final int OK_CANCEL_OPTION
- See Also:
- Constant Field Values
-
YES_OPTION
public static final int YES_OPTION
- See Also:
- Constant Field Values
-
YES_NO_OPTION
public static final int YES_NO_OPTION
- See Also:
- Constant Field Values
-
YES_NO_CANCEL_OPTION
public static final int YES_NO_CANCEL_OPTION
- See Also:
- Constant Field Values
-
NO_OPTION
public static final int NO_OPTION
- See Also:
- Constant Field Values
-
CLOSED_OPTION
public static final int CLOSED_OPTION
- See Also:
- Constant Field Values
-
DEFAULT_OPTION
public static final int DEFAULT_OPTION
- See Also:
- Constant Field Values
-
UNINITIALIZED_VALUE
public static final java.lang.Object UNINITIALIZED_VALUE
-
ERROR_MESSAGE
public static final int ERROR_MESSAGE
- See Also:
- Constant Field Values
-
INFORMATION_MESSAGE
public static final int INFORMATION_MESSAGE
- See Also:
- Constant Field Values
-
PLAIN_MESSAGE
public static final int PLAIN_MESSAGE
- See Also:
- Constant Field Values
-
QUESTION_MESSAGE
public static final int QUESTION_MESSAGE
- See Also:
- Constant Field Values
-
WARNING_MESSAGE
public static final int WARNING_MESSAGE
- See Also:
- Constant Field Values
-
YES_STRING
public static final java.lang.String YES_STRING
-
NO_STRING
public static final java.lang.String NO_STRING
-
-
Constructor Detail
-
JmriJOptionPane
protected JmriJOptionPane()
-
-
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
, orCLOSED_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
, orCLOSED_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.
-
-