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 -
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.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.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidsetDefaultButton(StandardButton button) Sets the button as the default button.voidsetDefaultButton(WPushButton button) Sets the button as the default button.voidsetEscapeButton(StandardButton button) Sets the escape button.voidsetEscapeButton(WPushButton button) Sets the escape button.voidsetHidden(boolean hidden, WAnimation animation) Hides or shows the widget.voidSets the icon.final voidsetStandardButtons(StandardButton button, StandardButton... buttons) Sets standard buttons for the message box.voidsetStandardButtons(EnumSet<StandardButton> buttons) Sets standard buttons for the message box.voidsetText(CharSequence text) Sets the text for the message box.static final StandardButtonshow(CharSequence caption, CharSequence text, EnumSet<StandardButton> buttons) Convenience method to show a message box, blocking the current thread.static StandardButtonshow(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, resized, setAutoFocus, setClosable, setMaximumSize, setMinimumSize, setModal, setMovable, setResizable, setTitleBarEnabled, setWindowTitle, touchEnded, touchMoved, touchStartedMethods inherited from class eu.webtoolkit.jwt.WPopupWidget
getAdjust, getAnchorWidget, getAutoHideDelay, getOrientation, hidden, isTransient, setAdjust, setAdjust, setAnchorWidget, setAnchorWidget, setTransient, setTransient, shownMethods 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, setParentWidget, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignmentMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods inherited from class eu.webtoolkit.jwt.WObject
resendFormData, 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.- See Also:
-
getButtons
Returns the buttons. -
getButton
Returns the button widget for the given standard button.Returns
nullif 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.OkorStandardButton.Yesresult. -
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.CancelorStandardButton.Noresult. -
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.CancelorStandardButton.Noresult. -
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 ofWDialogfor 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:WWidgetHides 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(). -
render
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
-