Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class MessageBox

extends Dialog
Class Inheritance
Imports
java.util.*, org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

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 Note

This class is not intended to be subclassed.

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

Field Summary

Modifier and TypeField and Description
pack-priv long
private Map<Integer, String>
pack-priv String
Inherited from org.eclipse.swt.widgets.Dialog:
parentstyletitle

Constructor Summary

AccessConstructor and Description
public
MessageBox(Shell
a shell which will be the parent of the new instance
parent
)

Constructs a new instance of this class given only its parent.

public
MessageBox(Shell
a shell which will be the parent of the new instance
parent
,
int
the style of dialog to construct
style
)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Method Summary

Modifier and TypeMethod and Description
private static int
checkStyle(int style)

private void
createButtons(int alignment)

private byte[]
getLabelForButton(int buttonId, String messageId)

public String

Returns:

the message
getMessage
()

Returns the dialog's message, or an empty string if it does not have one.

public int

Returns:

the ID of the button that was selected to dismiss the message box (e.g. SWT.OK, SWT.CANCEL, etc.)
open
()

Makes the dialog visible and brings it to the front of the display.

public void
setButtonLabels(Map<Integer, String>
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
labels
)

Set custom text for MessageDialog's buttons:

public void
setMessage(String
the message
string
)

Sets the dialog's message, which is a description of the purpose for which it was opened.

Inherited from org.eclipse.swt.widgets.Dialog:
checkParentcheckStylecheckSubclasserrorgetParentgetStylegetTextsetText

Field Detail

handleback to summary
pack-priv long handle
labelsback to summary
private Map<Integer, String> labels
messageback to summary
pack-priv String message

Constructor Detail

MessageBoxback to summary
public MessageBox(Shell parent)

Constructs a new instance of this class given only its parent.

Parameters
parent:Shell

a shell which will be the parent of the new instance

Exceptions
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
MessageBoxback to summary
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:Shell

a shell which will be the parent of the new instance

style:int

the style of dialog to construct

Exceptions
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

checkStyleback to summary
private static int checkStyle(int style)
createButtonsback to summary
private void createButtons(int alignment)
getLabelForButtonback to summary
private byte[] getLabelForButton(int buttonId, String messageId)
getMessageback to summary
public 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:String

the message

openback to summary
public int open()

Makes the dialog visible and brings it to the front of the display.

Returns:int

the ID of the button that was selected to dismiss the message box (e.g. SWT.OK, SWT.CANCEL, etc.)

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the dialog has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog
setButtonLabelsback to summary
public void setButtonLabels(Map<Integer, String> labels)

Set custom text for MessageDialog's buttons:

Parameters
labels:Map<Integer, String>

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
Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if labels is null
Since
3.121
setMessageback to summary
public void setMessage(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:String

the message

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the string is null