Class WMessageBox
- java.lang.Object
-
public class WMessageBox extends WDialog
A standard dialog for confirmation or to get simple user input.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 thebuttonClicked()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 theWDialog#exec(), it suffers from the same scalability issues as well as limitations. See documentation ofWDialogfor 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
WMessageBoxbuttons 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
Constructors Constructor Description WMessageBox()Creates an empty message box.WMessageBox(java.lang.CharSequence caption, java.lang.CharSequence text, Icon icon, StandardButton button, StandardButton... buttons)Creates a message box with given caption, text, icon, and buttons.WMessageBox(java.lang.CharSequence caption, java.lang.CharSequence text, Icon icon, java.util.EnumSet<StandardButton> buttons)Creates a message box with given caption, text, icon, and buttons.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WPushButtonaddButton(StandardButton result)Adds a standard button.WPushButtonaddButton(WPushButton button, StandardButton result)Adds a custom button.WPushButtonaddButton(java.lang.CharSequence text, StandardButton result)Adds a custom button with given text.Signal1<StandardButton>buttonClicked()Signal emitted when a button is clicked.WPushButtongetButton(StandardButton b)Returns the button widget for the given standard button.StandardButtongetButtonResult()Returns the result of this message box.java.util.List<WPushButton>getButtons()Returns the buttons.WPushButtongetDefaultButton()Returns the default button.WPushButtongetEscapeButton()Returns the escape button.IcongetIcon()Returns the icon.java.util.EnumSet<StandardButton>getStandardButtons()Returns the standard buttons.WStringgetText()Returns the message box text.WTextgetTextWidget()Returns the text widget.protected voidrender(java.util.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.voidsetIcon(Icon icon)Sets the icon.voidsetStandardButtons(StandardButton button, StandardButton... buttons)Sets standard buttons for the message box.voidsetStandardButtons(java.util.EnumSet<StandardButton> buttons)Sets standard buttons for the message box.voidsetText(java.lang.CharSequence text)Sets the text for the message box.static StandardButtonshow(java.lang.CharSequence caption, java.lang.CharSequence text, java.util.EnumSet<StandardButton> buttons)Convenience method to show a message box, blocking the current thread.static StandardButtonshow(java.lang.CharSequence caption, java.lang.CharSequence text, java.util.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, touchStarted
-
Methods inherited from class eu.webtoolkit.jwt.WPopupWidget
getAdjust, getAnchorWidget, getAutoHideDelay, getOrientation, hidden, isTransient, setAdjust, setAdjust, 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, setParentWidget, 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, 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, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
-
-
-
Constructor Detail
-
WMessageBox
public WMessageBox()
Creates an empty message box.
-
WMessageBox
public WMessageBox(java.lang.CharSequence caption, java.lang.CharSequence text, Icon icon, java.util.EnumSet<StandardButton> buttons)Creates a message box with given caption, text, icon, and buttons.
-
WMessageBox
public WMessageBox(java.lang.CharSequence caption, java.lang.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 Detail
-
setText
public void setText(java.lang.CharSequence text)
Sets the text for the message box.
-
getText
public WString getText()
Returns the message box text.
-
getTextWidget
public WText getTextWidget()
Returns the text widget.This may be useful to customize the style or layout of the displayed text.
-
setIcon
public void setIcon(Icon icon)
Sets the icon.
-
getIcon
public Icon getIcon()
Returns the icon.
-
addButton
public WPushButton addButton(WPushButton button, StandardButton result)
Adds a custom button.When the button is clicked, the associated result will be returned.
-
addButton
public WPushButton addButton(java.lang.CharSequence text, StandardButton result)
Adds a custom button with given text.When the button is clicked, the associated result will be returned.
-
addButton
public WPushButton addButton(StandardButton result)
Adds a standard button.
-
setStandardButtons
public void setStandardButtons(java.util.EnumSet<StandardButton> buttons)
Sets standard buttons for the message box.
-
setStandardButtons
public final void setStandardButtons(StandardButton button, StandardButton... buttons)
Sets standard buttons for the message box.
-
getStandardButtons
public java.util.EnumSet<StandardButton> getStandardButtons()
Returns the standard buttons.
-
getButtons
public java.util.List<WPushButton> getButtons()
Returns the buttons.
-
getButton
public WPushButton getButton(StandardButton b)
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
public void setDefaultButton(WPushButton button)
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
public void setDefaultButton(StandardButton button)
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
public WPushButton getDefaultButton()
Returns the default button.- See Also:
setDefaultButton(WPushButton button)
-
setEscapeButton
public void setEscapeButton(WPushButton button)
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
public void setEscapeButton(StandardButton button)
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
public WPushButton getEscapeButton()
Returns the escape button.- See Also:
setEscapeButton(WPushButton button)
-
getButtonResult
public StandardButton getButtonResult()
Returns the result of this message box.This value is only defined after the dialog is finished.
-
show
public static StandardButton show(java.lang.CharSequence caption, java.lang.CharSequence text, java.util.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(java.lang.CharSequence caption, java.lang.CharSequence text, java.util.EnumSet<StandardButton> buttons)
Convenience method to show a message box, blocking the current thread.
-
buttonClicked
public Signal1<StandardButton> buttonClicked()
Signal emitted when a button is clicked.
-
setHidden
public void setHidden(boolean hidden, WAnimation animation)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
protected void render(java.util.EnumSet<RenderFlag> flags)
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.
-
-