Package gr.zeus.ui

Class JMessage

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

public final class JMessage extends JDialog
This component is similar to javax.swing.JOptionPane component. It can be used to display message and error dialogs. The main features of JMessage are:
  • Displays simple messages and the stacktrace of an exception
  • Supports html text for messages with build-in plain text conversion
  • The dialogs are modal. In addition they stay on top of other windows at all times
  • Supports for JOptionPane OK,CANCEL,YES,NO buttons
  • Selects a default button in the dialog
  • Supports all JOptionPane messageType(s) & optionType(s)
  • Uses UI default icons or user supplied icons
  • Uses localized dialog titles and button text, or user supplied text
  • Returns dialog status depending on which button was pressed

Since:
1.40
Author:
Gregory Kotsaftis
See Also:
  • Constructor Details

    • JMessage

      public JMessage(Frame parent, String message, String frameTitle, int messageType, int optionType, JMessage.JMessageButtonEnum defaultButton, Icon ico, Throwable ex, String okText, String cancelText, String yesText, String noText)
      Constructor. Creates fully customizable message dialog.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      frameTitle - The title for the frame, if null the default is used.
      messageType - Same as JOptionPane, one of: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      optionType - Same as JOptionPane, one of: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION
      defaultButton - The default selected button for the dialog, if null the default for optionType will be selected.
      ico - The custom icon to use, null means no icon.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.
      okText - Ok button text, if null the default is used.
      cancelText - Cancel button text, if null the default is used.
      yesText - Yes button text, if null the default is used.
      noText - No button text, if null the default is used.
  • Method Details

    • showErrorQuestionMessageY

      public static boolean showErrorQuestionMessageY(Frame parent, String message, Throwable ex)
      Shows a question window with YES/NO button options. Default button is YES. Also enables button to print the stacktrace of an exception. NOTE: On dialog close, it also returns false.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.

      Returns:
      true for YES, false for NO
    • showErrorMessage

      public static void showErrorMessage(Frame parent, String message)
      Wrapper method for showMessageDialog(). Shows an error window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
    • showErrorMessage

      public static void showErrorMessage(Frame parent, String message, Throwable ex)
      Wrapper method for showMessageDialog(). Shows an error window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.
    • showWarningMessage

      public static void showWarningMessage(Frame parent, String message)
      Wrapper method for showMessageDialog(). Shows a warning window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
    • showWarningMessage

      public static void showWarningMessage(Frame parent, String message, Throwable ex)
      Wrapper method for showMessageDialog(). Shows a warning window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.
    • showInfoMessage

      public static void showInfoMessage(Frame parent, String message)
      Wrapper method for showMessageDialog(). Shows an info window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
    • showInfoMessage

      public static void showInfoMessage(Frame parent, String message, Throwable ex)
      Wrapper method for showMessageDialog(). Shows an info window with default button option.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.
    • showQuestionMessageN

      public static boolean showQuestionMessageN(Frame parent, String message)
      Wrapper method for showMessageDialog(). Shows a question window with YES/NO button options. Default button is NO, e.g. for use with delete confirmation dialogs. NOTE: On dialog close, it also returns false.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.

      Returns:
      true for YES, false for NO
    • showQuestionMessageY

      public static boolean showQuestionMessageY(Frame parent, String message)
      Wrapper method for showMessageDialog(). Shows a question window with YES/NO button options. Default button is YES, e.g. for use with save confirmation dialogs. NOTE: On dialog close, it also returns false.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.

      Returns:
      true for YES, false for NO
    • showMessageDialog

      public static int showMessageDialog(Frame parent, String message, int messageType, int optionType)
      Factory method, create-show-return. Creates a dialog relative to parent frame using UI defaults for icon and a locale specific frame title.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      messageType - Same as JOptionPane, one of: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      optionType - Same as JOptionPane, one of: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION

      Returns:
      The status of the dialog depending on which button was pressed. Same as JOptionPane, one of: CANCEL_OPTION, NO_OPTION, YES_OPTION, OK_OPTION or CLOSED_OPTION if the dialog was closed.
    • showMessageDialog

      public static int showMessageDialog(Frame parent, String message, int messageType, int optionType, JMessage.JMessageButtonEnum defaultButton)
      Factory method, create-show-return. Creates a dialog relative to parent frame using UI defaults for icon and a locale specific frame title. Use JMessageButtonEnum to setup the default button.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      messageType - Same as JOptionPane, one of: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      optionType - Same as JOptionPane, one of: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION
      defaultButton - The default selected button for the dialog, if null the default for optionType will be selected.

      Returns:
      The status of the dialog depending on which button was pressed. Same as JOptionPane, one of: CANCEL_OPTION, NO_OPTION, YES_OPTION, OK_OPTION or CLOSED_OPTION if the dialog was closed.
    • showMessageDialog

      public static int showMessageDialog(Frame parent, String message, int messageType, int optionType, Throwable ex)
      Factory method, create-show-return. Creates a dialog relative to parent frame using UI defaults for icon and a locale specific frame title. Also enables button to print the stacktrace of an exception.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      messageType - Same as JOptionPane, one of: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      optionType - Same as JOptionPane, one of: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.

      Returns:
      The status of the dialog depending on which button was pressed. Same as JOptionPane, one of: CANCEL_OPTION, NO_OPTION, YES_OPTION, OK_OPTION or CLOSED_OPTION if the dialog was closed.
    • showMessageDialog

      public static int showMessageDialog(Frame parent, String message, String frameTitle, int messageType, int optionType, JMessage.JMessageButtonEnum defaultButton, Icon ico, Throwable ex, String okText, String cancelText, String yesText, String noText)
      Factory method, create-show-return. Creates fully customizable message dialog.

      Parameters:
      parent - The parent relative frame, can be null.
      message - The message to display, can be plain or html.
      frameTitle - The title for the frame, if null the default is used.
      messageType - Same as JOptionPane, one of: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
      optionType - Same as JOptionPane, one of: DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, OK_CANCEL_OPTION
      defaultButton - The default selected button for the dialog, if null the default for optionType will be selected.
      ico - The custom icon to use, null means no icon.
      ex - An exception to display it's stacktrace, null will disable the stacktrace button functionality.
      okText - Ok button text, if null the default is used.
      cancelText - Cancel button text, if null the default is used.
      yesText - Yes button text, if null the default is used.
      noText - No button text, if null the default is used.

      Returns:
      The status of the dialog depending on which button was pressed. Same as JOptionPane, one of: CANCEL_OPTION, NO_OPTION, YES_OPTION, OK_OPTION or CLOSED_OPTION if the dialog was closed.
    • getReturnStatus

      public int getReturnStatus()
      Returns the status of the dialog depending on which button was pressed.

      Returns:
      Same as JOptionPane, one of: CANCEL_OPTION, NO_OPTION, YES_OPTION, OK_OPTION or CLOSED_OPTION if the dialog was closed.