Class WMessageBox
The messagebox shows a message in a dialog window, with a number of buttons. These buttons may be standard buttons, or customized.
A messagebox is (usually) modal, and can be instantiated synchronously or asynchronously.
When using a messagebox asynchronously, there is no API call that waits for the messagebox to
be processed. Instead, the usage is similar to instantiating a WDialog
(or any other
widget). You need to connect to the buttonClicked()
signal to
interpret the result and delete the message box.
The synchronous use of a messagebox involves the use of the static WWidget.show()
method, which blocks the current thread until the user has processed the messabebox. Since this
uses the WDialog#exec()
, it suffers from the same
scalability issues as well as limitations. See documentation of WDialog
for more details.
This will show a message box that looks like this:
Example of a WMessageBox (default) | Example of a WMessageBox (polished) |
i18n
The strings used in the WMessageBox
buttons can be translated by overriding the
default values for the following localization keys:
- Wt.WMessageBox.Abort: Abort
- Wt.WMessageBox.Cancel: Cancel
- Wt.WMessageBox.Ignore: Ignore
- Wt.WMessageBox.No: No
- Wt.WMessageBox.NoToAll: No To All
- Wt.WMessageBox.Ok: Ok
- Wt.WMessageBox.Retry: Retry
- Wt.WMessageBox.Yes: Yes
- Wt.WMessageBox.YesToAll: Yes to All
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
ConstructorDescriptionCreates an empty message box.WMessageBox
(CharSequence caption, CharSequence text, Icon icon, StandardButton button, StandardButton... buttons) Creates a message box with given caption, text, icon, and buttons.WMessageBox
(CharSequence caption, CharSequence text, Icon icon, EnumSet<StandardButton> buttons) Creates a message box with given caption, text, icon, and buttons. -
Method Summary
Modifier and TypeMethodDescriptionaddButton
(StandardButton result) Adds a standard button.void
addButton
(WPushButton button, StandardButton result) Adds a custom button.addButton
(CharSequence text, StandardButton result) Adds a custom button with given text.Signal emitted when a button is clicked.Returns the button widget for the given standard button.Returns the result of this message box.Returns the buttons.Returns the default button.Returns the escape button.getIcon()
Returns the icon.Returns the standard buttons.getText()
Returns the message box text.Returns the text widget.void
setDefaultButton
(StandardButton button) Sets the button as the default button.void
setDefaultButton
(WPushButton button) Sets the button as the default button.void
setEscapeButton
(StandardButton button) Sets the escape button.void
setEscapeButton
(WPushButton button) Sets the escape button.void
setHidden
(boolean hidden, WAnimation animation) Hides or shows the widget.void
Sets the icon.final void
setStandardButtons
(StandardButton button, StandardButton... buttons) Sets standard buttons for the message box.void
setStandardButtons
(EnumSet<StandardButton> buttons) Sets standard buttons for the message box.void
setText
(CharSequence text) Sets the text for the message box.static final StandardButton
show
(CharSequence caption, CharSequence text, EnumSet<StandardButton> buttons) Convenience method to show a message box, blocking the current thread.static StandardButton
show
(CharSequence caption, CharSequence text, EnumSet<StandardButton> buttons, WAnimation animation) Convenience method to show a message box, blocking the current thread.Methods inherited from class eu.webtoolkit.jwt.WDialog
accept, done, enterPressed, escapePressed, exec, exec, finished, getContents, getFooter, getResult, getTitleBar, getWindowTitle, isClosable, isModal, isMovable, isResizable, isTitleBarEnabled, keyPressed, keyWentDown, keyWentUp, moved, onPathChange, positionAt, positionAt, raiseToFront, reject, rejectWhenEscapePressed, rejectWhenEscapePressed, remove, render, resized, setAutoFocus, setClosable, setMaximumSize, setMinimumSize, setModal, setMovable, setResizable, setTitleBarEnabled, setWindowTitle, touchEnded, touchMoved, touchStarted
Methods inherited from class eu.webtoolkit.jwt.WPopupWidget
getAnchorWidget, getAutoHideDelay, getOrientation, hidden, isTransient, setAnchorWidget, setAnchorWidget, setTransient, setTransient, shown
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, load, propagateSetEnabled, propagateSetVisible, refresh, removeStyleClass, removeWidget, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setObjectName, setOffsets, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
Constructor Details
-
WMessageBox
public WMessageBox()Creates an empty message box. -
WMessageBox
public WMessageBox(CharSequence caption, CharSequence text, Icon icon, EnumSet<StandardButton> buttons) Creates a message box with given caption, text, icon, and buttons. -
WMessageBox
public WMessageBox(CharSequence caption, CharSequence text, Icon icon, StandardButton button, StandardButton... buttons) Creates a message box with given caption, text, icon, and buttons.Calls
this(caption, text, icon, EnumSet.of(button, buttons))
-
-
Method Details
-
setText
Sets the text for the message box. -
getText
Returns the message box text. -
getTextWidget
Returns the text widget.This may be useful to customize the style or layout of the displayed text.
-
setIcon
Sets the icon. -
getIcon
Returns the icon. -
addButton
Adds a custom button.When the button is clicked, the associated result will be returned.
-
addButton
Adds a custom button with given text.When the button is clicked, the associated result will be returned.
-
addButton
Adds a standard button. -
setStandardButtons
Sets standard buttons for the message box. -
setStandardButtons
Sets standard buttons for the message box. -
getStandardButtons
Returns the standard buttons. -
getButtons
Returns the buttons. -
getButton
Returns the button widget for the given standard button.Returns
null
if the button isn't in the message box.This may be useful to customize the style or layout of the button.
-
setDefaultButton
Sets the button as the default button.The default button is pressed when the user presses enter. Only one button can be the default button.
If no default button is set, JWt will take a button that is associated with a
StandardButton.Ok
orStandardButton.Yes
result. -
setDefaultButton
Sets the button as the default button.The default button is pressed when the user presses enter. Only one button can be the default button.
The default value is 0 (no default button).
-
getDefaultButton
Returns the default button.- See Also:
-
setEscapeButton
Sets the escape button.The escape button is pressed when the user presses escapes.
If no escape button is set, JWt will take a button that is associated with a
StandardButton.Cancel
orStandardButton.No
result. -
setEscapeButton
Sets the escape button.The escape button is pressed when the user presses escapes.
If no escape button is set, JWt will take a button that is associated with a
StandardButton.Cancel
orStandardButton.No
result. -
getEscapeButton
Returns the escape button.- See Also:
-
getButtonResult
Returns the result of this message box.This value is only defined after the dialog is finished.
-
show
public static StandardButton show(CharSequence caption, CharSequence text, EnumSet<StandardButton> buttons, WAnimation animation) Convenience method to show a message box, blocking the current thread.Show a message box, blocking the current thread until the message box is closed, and return the result. The use of this method is not recommended since it uses
WDialog#exec()
. See documentation ofWDialog
for detailed information.This functionality is only available on Servlet 3.0 compatible servlet containers.
-
show
public static final StandardButton show(CharSequence caption, CharSequence text, EnumSet<StandardButton> buttons) Convenience method to show a message box, blocking the current thread. -
buttonClicked
Signal emitted when a button is clicked. -
setHidden
Description copied from class:WWidget
Hides or shows the widget.Hides or show the widget (including all its descendant widgets). When setting
hidden
=false
, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked usingisVisible()
.
-