Class MessageBox


  • public class MessageBox
    extends Dialog
    Instances of this class are used to inform or warn the user.
    Styles:
    ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING
    OK, OK | CANCEL
    YES | NO, YES | NO | CANCEL
    RETRY | CANCEL
    ABORT | RETRY | IGNORE
    Events:
    (none)

    Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING and ICON_WORKING may be specified.

    IMPORTANT: This class is not intended to be subclassed.

    See Also:
    SWT Example: ControlExample, Dialog tab, Sample code and further information
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageBox​(Shell parent)
      Constructs a new instance of this class given only its parent.
      MessageBox​(Shell parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getMessage()
      Returns the dialog's message, or an empty string if it does not have one.
      int open()
      Makes the dialog visible and brings it to the front of the display.
      void setButtonLabels​(java.util.Map<java.lang.Integer,​java.lang.String> labels)
      Set custom text for MessageDialog's buttons:
      void setMessage​(java.lang.String string)
      Sets the dialog's message, which is a description of the purpose for which it was opened.
      • Methods inherited from class java.lang.Object

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

      • MessageBox

        public MessageBox​(Shell parent)
        Constructs a new instance of this class given only its parent.
        Parameters:
        parent - a shell which will be the parent of the new instance
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parent is null
        SWTException -
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
        • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
      • MessageBox

        public MessageBox​(Shell parent,
                          int style)
        Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

        The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

        Parameters:
        parent - a shell which will be the parent of the new instance
        style - the style of dialog to construct
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parent is null
        SWTException -
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
        • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
        See Also:
        SWT.ICON_ERROR, SWT.ICON_INFORMATION, SWT.ICON_QUESTION, SWT.ICON_WARNING, SWT.ICON_WORKING, SWT.OK, SWT.CANCEL, SWT.YES, SWT.NO, SWT.ABORT, SWT.RETRY, SWT.IGNORE
    • Method Detail

      • getMessage

        public java.lang.String getMessage()
        Returns the dialog's message, or an empty string if it does not have one. The message is a description of the purpose for which the dialog was opened. This message will be visible in the dialog while it is open.
        Returns:
        the message
      • setMessage

        public void setMessage​(java.lang.String string)
        Sets the dialog's message, which is a description of the purpose for which it was opened. This message will be visible on the dialog while it is open.
        Parameters:
        string - the message
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the string is null
      • open

        public int open()
        Makes the dialog visible and brings it to the front of the display.
        Returns:
        the ID of the button that was selected to dismiss the message box (e.g. SWT.OK, SWT.CANCEL, etc.)
        Throws:
        SWTException -
        • ERROR_WIDGET_DISPOSED - if the dialog has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
      • setButtonLabels

        public void setButtonLabels​(java.util.Map<java.lang.Integer,​java.lang.String> labels)
        Set custom text for MessageDialog's buttons:
        Parameters:
        labels - a Map where a valid 'key' is from below listed styles:
        • SWT#OK
        • SWT#CANCEL
        • SWT#YES
        • SWT#NO
        • SWT#ABORT
        • SWT#RETRY
        • SWT#IGNORE
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if labels is null
        Since:
        3.121