public class MessageDialog extends Dialog
MessageDialogs are used to show some information message to the user, warn him about application errors or problems, and let him choose what action to take.
A MessageDialog is a simple Dialog with an image representing the type of
the message (error, warning, etc... take a look at MessageType
), the message text and some Buttons to let the user decide how
to respond to the message. The ButtonsType
enumeration
can be used to choose among some common combination of Buttons, but you can
also add other Buttons via the usual Dialog's
addButton()
method.
Optionally you can provide a secondary text that displays more information about the message. Both the main message and the secondary text can be formatted with Pango markup.
In most cases, MessageDialog is a modal Dialog that you will show with the
run()
method, and hide()
once the user has
responded to it, much like in the following example:
// create the Dialog MessageDialog dialog = new MessageDialog(window, true, MessageType.WARNING, ButtonsType.OK_CANCEL, "Do you want to delete file.txt?"); dialog.setSecondaryText("If you delete that file, you will loose all the information there"); // Show the Dialog ResponseType choice = dialog.run(); // Hide it once the user has responded dialog.hide(); // process if (choice == ResponseType.OK) { // delete the file... } else { // cancel... }
MessageType
,
ButtonsType
Dialog.Response
Window.ConfigureEvent, Window.DeleteEvent
Widget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.Destroy, Widget.Draw, Widget.EnterNotifyEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.QueryTooltip, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent
Constructor and Description |
---|
MessageDialog(Window parent,
boolean modal,
MessageType type,
ButtonsType buttons,
String message)
Create a new MessageDialog.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getSecondaryUseMarkup()
Whether the secondary text is to be interpreted as marked up with
Pango's text markup language.
|
boolean |
getUseMarkup()
Whether the message text is to be interpreted as marked up with Pango's
text markup language.
|
void |
setImage(Widget image)
Set the Widget to be used as the image for the MessageDialog.
|
void |
setSecondaryText(String text)
Sets the secondary text for the MessageDialog.
|
void |
setSecondaryText(String text,
boolean markup)
Sets the secondary text for the MessageDialog.
|
void |
setSecondaryUseMarkup(boolean setting)
Set whether the secondary text is to be parsed as containing markup in
Pango's text markup language.
|
void |
setUseMarkup(boolean setting)
Set whether the message text is to be parsed as containing markup in
Pango's text markup language.
|
add, addButton, addButton, addButton, connect, emitResponse, run, setDefaultResponse
addAcceleratorGroup, connect, connect, getHeight, getMaximized, getPositionX, getPositionY, getScreen, getWidth, move, present, resize, setDecorated, setDefaultSize, setFullscreen, setGravity, setHasResizeGrip, setIcon, setIcon, setKeepAbove, setKeepBelow, setMaximize, setModal, setPosition, setResizable, setSkipPagerHint, setSkipTaskbarHint, setStick, setTitle, setTransientFor, setTypeHint
getChildren, remove, setBorderWidth
activate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, destroy, getAllocatedHeight, getAllocatedWidth, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getPreferredHeightForWidthMinimum, getPreferredHeightForWidthNatural, getPreferredHeightMinimum, getPreferredHeightNatural, getPreferredWidthForHeightMinimum, getPreferredWidthForHeightNatural, getPreferredWidthMinimum, getPreferredWidthNatural, getRequestMode, getRequisition, getSensitive, getStyleContext, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, overrideBackground, overrideColor, overrideFont, queueDraw, queueDrawArea, realize, setAlignHorizontal, setAlignVertical, setCanDefault, setCanFocus, setEvents, setExpandHorizontal, setExpandVertical, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAll
public MessageDialog(Window parent, boolean modal, MessageType type, ButtonsType buttons, String message)
parent
- Transient parent for the MessageDialog. It can be
null
, but if you have a parent Window you
should pass it here to force the Dialog to be on top of the
parent Window and to be presented to the user when they
select the parent Window.modal
- Whether the Dialog will be modal.type
- Type of the Dialogbuttons
- Set of Buttons to be presented.message
- The main message of the Dialog. If you want to use a String
formatted with the Pango markup, you will need to call
setUseMarkup()
later.public boolean getSecondaryUseMarkup()
public boolean getUseMarkup()
public void setImage(Widget image)
types
, the image is set to an appropriate
icon from the Stock. That is what you must use in most cases. However,
there can be some cases where you want to provide your own Widget. In
that cases, you should set the message type to
OTHER
when creating the Dialog.public void setSecondaryText(String text)
setSecondaryUseMarkup()
or call
setSecondaryText(String,
true)
instead.public void setSecondaryText(String text, boolean markup)
Note that setting a secondary text makes the primary text become bold, unless you are using markup.
text
- The text to be used as secondary text.markup
- Whether to interpret this secondary text as marked up with
Pango's text markup language.public void setSecondaryUseMarkup(boolean setting)
public void setUseMarkup(boolean setting)
setting
- If setting is true, then any markup included in the text is
interpreted as such. If its set to false, markup is ignored
and included as-is.