Class WWidget
- Direct Known Subclasses:
WCompositeWidget,WWebWidget
The user-interface is organized in a tree structure, in which each node is a widget. All
widgets, except for the application's root widget and dialogs, have a parent which is
usually a WContainerWidget.
This is an abstract base class. Implementations derive either from the abstract WWebWidget (for basic widgets with a direct HTML counter-part) or from the abstract WCompositeWidget (for anything else). To add a WWidget to a parent container add the widget to
the parent using WContainerWidget#addWidget().
Alternatively, you may add the widget to a layout manager set for a WContainerWidget.
A widget provides methods to manage its decorative style base on CSS. It also provides access to CSS-based layout, which you may not use when the widget is not inserted into a layout manager.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWWidget()Creates a widget.protectedWWidget(WContainerWidget parentContainer) Creates a widget. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidacceptDrops(String mimeType) Sets a mime type to be accepted for dropping.voidacceptDrops(String mimeType, String hoverStyleClass) Sets a mime type to be accepted for dropping.protected final WCssTextRuleaddCssRule(String selector, String declarations) protected WCssTextRuleaddCssRule(String selector, String declarations, String ruleName) voidaddJSignal(AbstractEventSignal signal) final voidaddStyleClass(String styleClass) Adds a CSS style class.abstract voidaddStyleClass(String styleClass, boolean force) Adds a CSS style class.voidanimateHide(WAnimation animation) Hides the widget using an animation.voidanimateShow(WAnimation animation) Shows the widget using an animation.voidApply the theme style scheduled.protected intboxBorder(Orientation orientation) Returns the widget's built-in border width.protected intboxPadding(Orientation orientation) Returns the widget's built-in padding.abstract voidcallJavaScriptMember(String name, String args) Calls a JavaScript member.createJavaScript(StringBuilder js, String insertJS) voiddisable()Disable thes widget.abstract voiddoJavaScript(String js) Executes the given JavaScript statements when the widget is rendered or updated.protected voiddropEvent(WDropEvent event) Handles a drop event.voidenable()Enables the widget.protected abstract voidProgresses to an Ajax-enabled widget.abstract WWidgetFinds a descendent widget by name.abstract WWidgetFinds a descendent widget by id.abstract StringgetAttributeValue(String name) Returns an attribute value.abstract intReturns child widgets.Returns the sides that should remain empty.abstract WCssDecorationStyleReturns the decoration style of this widget.protected voidgetDropTouch(String sourceId, String mimeType, WTouchEvent event) abstract SideReturns the CSS float side.abstract WLengthReturns the height.abstract StringgetJavaScriptMember(String name) Returns the value of a JavaScript member.getJsRef()Returns a JavaScript expression to the corresponding DOM node.abstract WLengthReturns the CSS line height for contained text.abstract WLengthReturns a CSS margin set.abstract WLengthReturns the maximum height.abstract WLengthReturns the maximum width.abstract WLengthReturns the minimum height.abstract WLengthReturns the minimum width.abstract WLengthReturns a CSS offset.Returns the parent widget.abstract PositionSchemeReturns the CSS position scheme.abstract intReturns the margin around the viewport within which the widget is considered visible.abstract StringReturns the CSS style class.abstract intReturns the tab index.abstract WStringReturns the tooltip.abstract AlignmentFlagReturns the vertical alignment.abstract WLengthReturns the fixed vertical alignment that was set.abstract WLengthgetWidth()Returns the width.abstract booleanhasFocus()Returns whether the widget currently has the focus.abstract booleanhasStyleClass(String styleClass) Returns whether the widget has a style class.voidhide()Hides the widget.voidStreams the (X)HTML representation.abstract booleanReturns whether the widget can receive focus.abstract booleanReturns whether the widget is set disabled.abstract booleanReturns whether the widget is enabled.booleanprotected booleanabstract booleanisHidden()Returns whether the widget is set hidden.abstract booleanReturns whether the widget keeps its geometry when hidden.abstract booleanisInline()Returns whether the widget is displayed inline or as block.booleanReturns whether the widget is layout size aware.abstract booleanisLoaded()Returns whether this widget has been loaded.abstract booleanisPopup()Returns whether the widget is overlayed.booleanReturns whether the widget is rendered.abstract booleanReturns whether scroll visibility detection is enabled for this widget.abstract booleanReturns whether this widget is currently considered scroll visible.abstract booleanSet focus on the widget's first descendant.abstract booleanReturns whether this widget is currently styled by the chosen theme.abstract booleanReturns whether the widget is visible.protected voidlayoutSizeChanged(int width, int height) Virtual method that indicates a size change.abstract voidload()Loads content just before the widget is used.booleanfinal voidpositionAt(WWidget widget) Positions a widget next to another widget.final voidpositionAt(WWidget widget, Orientation orientation) Positions a widget next to another widget.final voidpositionAt(WWidget widget, Orientation orientation, Orientation adjustOrientation, Orientation... adjustOrientations) Positions a widget next to another widget.voidpositionAt(WWidget widget, Orientation orientation, EnumSet<Orientation> adjustOrientations) Positions a widget next to another widget.protected abstract voidpropagateSetEnabled(boolean enabled) Propagates that a widget was enabled or disabled through children.protected abstract voidpropagateSetVisible(boolean visible) voidrefresh()Refresh the widget.voidremove()Destructor.Removes the widget from its parent.final voidremoveStyleClass(String styleClass) Removes a CSS style class.abstract voidremoveStyleClass(String styleClass, boolean force) Removes a CSS style class.removeWidget(WWidget widget) Removes a child widget.protected final voidrender(RenderFlag flag, RenderFlag... flags) Renders the widget.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidresize(int widthPixels, int heightPixels) Resizes the widget.voidResizes the widget.protected final voidSchedules rerendering of the widget.protected final voidscheduleRender(eu.webtoolkit.jwt.RepaintFlag flag, eu.webtoolkit.jwt.RepaintFlag... flags) Schedules rerendering of the widget.protected voidscheduleRender(EnumSet<eu.webtoolkit.jwt.RepaintFlag> flags) Schedules rerendering of the widget.voidscheduleThemeStyleApply(WTheme theme, WWidget child, int role) Schedules a theme style to be applied at the next render.Signaltriggered when the scroll visibility of this widget changes.abstract voidsetAttributeValue(String name, String value) Sets an attribute value.abstract voidsetCanReceiveFocus(boolean enabled) Sets whether the widget can receive focus.final voidsetClearSides(Side side, Side... sides) Sets the sides that should be cleared of floats.abstract voidsetClearSides(EnumSet<Side> sides) Sets the sides that should be cleared of floats.abstract voidSets a CSS decoration style.final voidsetDeferredToolTip(boolean enable) Enable deferred tooltip.abstract voidsetDeferredToolTip(boolean enable, TextFormat textFormat) Enable deferred tooltip.abstract voidsetDisabled(boolean disabled) Sets whether the widget is disabled.abstract voidsetFloatSide(Side s) Specifies a CSS float side.voidsetFocus()Sets focus.abstract voidsetFocus(boolean focus) Sets focus.voidSets the height.final voidsetHidden(boolean hidden) Hides or shows the widget.abstract voidsetHidden(boolean hidden, WAnimation animation) Hides or shows the widget.abstract voidsetHiddenKeepsGeometry(boolean enabled) Sets whether the widget keeps its geometry when hidden.abstract voidSets the CSS Id.abstract voidsetInline(boolean inlined) Sets whether the widget is displayed inline or as a block.abstract voidsetJavaScriptMember(String name, String value) Sets a JavaScript member.protected voidsetLayoutSizeAware(boolean aware) Sets the widget to be aware of its size set by a layout manager.abstract voidsetLineHeight(WLength height) Sets the CSS line height for contained text.final voidsetMargin(int pixels) Sets CSS margins around the widget.final voidSets CSS margins around the widget.voidSets CSS margins around the widget.final voidSets CSS margins around the widget.final voidSets CSS margins around the widget.abstract voidSets CSS margins around the widget.abstract voidsetMaximumSize(WLength width, WLength height) Sets a maximum size.abstract voidsetMinimumSize(WLength width, WLength height) Sets a minimum size.final voidsetOffsets(int pixels) Sets CSS offsets for a non-statically positioned widget.final voidsetOffsets(int pixels, Side side, Side... sides) Sets CSS offsets for a non-statically positioned widget.voidsetOffsets(int pixels, EnumSet<Side> sides) Sets CSS offsets for a non-statically positioned widget.final voidsetOffsets(WLength offset) Sets CSS offsets for a non-statically positioned widget.final voidsetOffsets(WLength offset, Side side, Side... sides) Sets CSS offsets for a non-statically positioned widget.abstract voidsetOffsets(WLength offset, EnumSet<Side> sides) Sets CSS offsets for a non-statically positioned widget.abstract voidsetPopup(boolean popup) Lets the widget overlay over other sibling widgets.abstract voidsetPositionScheme(PositionScheme scheme) Sets the CSS position scheme.abstract voidsetScrollVisibilityEnabled(boolean enabled) Sets whether scroll visibility detection is enabled for this widget.abstract voidsetScrollVisibilityMargin(int margin) Sets the margin around the viewport within which the widget is considered visible.abstract voidsetSelectable(boolean selectable) Sets as selectable.abstract voidsetStyleClass(String styleClass) Sets (one or more) CSS style classes.abstract voidsetTabIndex(int index) Sets the tab index.abstract voidsetThemeStyleEnabled(boolean enabled) Sets whether theme styling for a widget is enabled or disabled.final voidsetToolTip(CharSequence text) Sets a tooltip.abstract voidsetToolTip(CharSequence text, TextFormat textFormat) Sets a tooltip.final voidsetVerticalAlignment(AlignmentFlag alignment) Sets the vertical alignment.abstract voidsetVerticalAlignment(AlignmentFlag alignment, WLength length) Sets the vertical alignment.voidSets the width.voidshow()Shows the widget.voidstopAcceptDrops(String mimeType) Indicates that a mime type is no longer accepted for dropping.final voidtoggleStyleClass(String styleClass, boolean add) Toggles a CSS style class.voidtoggleStyleClass(String styleClass, boolean add, boolean force) Toggles a CSS style class.static WStringShort hand forWString#tr()Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, resendFormData, setFormData, setObjectName
-
Field Details
-
WT_GETEXTRAMS_JS
-
-
Constructor Details
-
WWidget
Creates a widget. -
WWidget
protected WWidget()Creates a widget.
-
-
Method Details
-
remove
public void remove()Destructor.Deletes a widget and all contained contents.
-
getParent
Returns the parent widget. -
getChildren
Returns child widgets.This returns widgets for which widget.
getParent()== this. -
removeWidget
Removes a child widget. -
removeFromParent
Removes the widget from its parent.This is equivalent to
getParent().removeWidget(this); -
setPositionScheme
Sets the CSS position scheme.Establishes how the widget must be layed-out relative to its siblings. The default position scheme is
PositionScheme.Static.This applies to CSS-based layout.
- See Also:
-
getPositionScheme
Returns the CSS position scheme.This applies to CSS-based layout.
- See Also:
-
setOffsets
Sets CSS offsets for a non-statically positioned widget.The argument
sidesmay be a combination ofSide.Left,Side.Right,Side.Top, andSide.Bottom.This applies only to widgets that have a position scheme that is
PositionScheme.Relative,PositionScheme.Absolute, orPositionScheme.Fixed, and has a slightly different meaning for these three cases.For a
relatively positionedwidget, an offset applies relative to the position the widget would have when layed-out using astaticposition scheme. The widget may be shifted to the left or right by specifying an offset for theleftorright) side. The widget may be shifted vertically, by specifying an offset for thetoporbottomside.For an
absolutely positionedwidget, an offset specifies a distance of the corresponding side of the widget with respect to the corresponding side of the reference parent widget. Thus, setting all offsets to 0 result in a widget that spans the entire reference widget. The reference parent widget is the first ancestor widget that is a table cell, or a widget with a relative, absolute or fixed position scheme.For an
fixed positionedwidget, an offset specifies a distance of the corresponding side of the widget with respect to the browser window, regardless of scrolling. Thus, setting all offsets to 0 result in a widget that spans the entire browser window.This applies to CSS-based layout.
- See Also:
-
setOffsets
Sets CSS offsets for a non-statically positioned widget. -
setOffsets
Sets CSS offsets for a non-statically positioned widget. -
setOffsets
Sets CSS offsets for a non-statically positioned widget.This is a convenience method for applying offsets in pixel units.
- See Also:
-
setOffsets
Sets CSS offsets for a non-statically positioned widget. -
setOffsets
public final void setOffsets(int pixels) Sets CSS offsets for a non-statically positioned widget. -
getOffset
Returns a CSS offset.This applies to CSS-based layout.
- See Also:
-
resize
Resizes the widget.Specifies a fixed size for this widget, setting CSS
widthandheightproperties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether the widget is a block or inline widget:
- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).
When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using
setLayoutSizeAware(). If you have defined a"wtResize()"JavaScript method for the widget, then this method will also be called.The default width and height of a widget is
WLength.Auto.- See Also:
-
resize
public void resize(int widthPixels, int heightPixels) Resizes the widget.This is a convenience method for resizing a widget using pixel units.
- See Also:
-
getWidth
Returns the width.Returns the width set for this widget. This is not a calculated width, based on layout, but the width as specified with
resize().This applies to CSS-based layout.
- See Also:
-
setWidth
Sets the width.This is a convenience method to change only the width of a widget, and is implemented as:
resize(width, height())- See Also:
-
getHeight
Returns the height.Returns the height set for this widget. This is not a calculated height, based on layout, but the height as specified previously with
resize().This applies to CSS-based layout.
- See Also:
-
setHeight
Sets the height.This is a convenience method to change only the height of a widget, and is implemented as:
resize(width(), height)This applies to CSS-based layout.
- See Also:
-
setMinimumSize
Sets a minimum size.Specifies a minimum size for this widget, setting CSS
min-widthandmin-heightproperties.The default minimum width and height is 0. The special value
WLength.Autoindicates that the initial width is used as minimum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is inserted in a layout manager, then the minimum size will be taken into account.
- See Also:
-
getMinimumWidth
Returns the minimum width.Returns the minimum width set for this widget with
setMinimumSize().- See Also:
-
getMinimumHeight
Returns the minimum height.Returns the minmum height set for this widget with
setMinimumSize().- See Also:
-
setMaximumSize
Sets a maximum size.Specifies a maximum size for this widget, setting CSS
max-widthandmax-heightproperties.The default the maximum width and height are
WLength.Auto, indicating no maximum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is a container widget that contains a layout manager, then setting a maximum size will have the effect of letting the size of the container to reflect the preferred size of the contents (rather than constraining the size of the children based on the size of the container), up to the specified maximum size.
- See Also:
-
getMaximumWidth
Returns the maximum width.Returns the maximum width set for this widget with
setMaximumSize().- See Also:
-
getMaximumHeight
Returns the maximum height.Returns the minmum height set for this widget with
setMaximumSize().- See Also:
-
positionAt
public void positionAt(WWidget widget, Orientation orientation, EnumSet<Orientation> adjustOrientations) Positions a widget next to another widget.Positions this absolutely positioned widget next to another
widget. Both widgets must be visible (including all their ancestors). The current widget is shown automatically if needed.When
orientation=Orientation.Vertical, the widget is displayed below the other widget (or above in case there is not enough room below). It is aligned so that the left edges align (or the right edges if there is not enough room to the right).Conversely, when
orientation=Orientation.Horizontal, the widget is displayed to the right of the other widget (or to the left in case there is not enough room to the right). It is aligned so that the top edges align (or the bottom edges if there is not enough room below).adjustOrientationsallows to specify the axes on which the widget can adjust it's position if there is not enough room next to the other widget, breaking the previous rules if necessary. For example, ifOrientation.Verticalflag ofadjustOrientationsis set, and part of the widget would be cut off by the top of the window, the widget would be move downward until the top of the widget is fully visible (or the widget reaches the bottom of the window). In that case, the widget would not be aligned with the other widget, in caseorientation=Orientation.Horizontal, or would be displayed over the other widget, in caseorientation=Orientation.Vertical.Note: This only works if JavaScript is available.
-
positionAt
public final void positionAt(WWidget widget, Orientation orientation, Orientation adjustOrientation, Orientation... adjustOrientations) Positions a widget next to another widget.Calls
positionAt(widget, orientation, EnumSet.of(adjustOrientation, adjustOrientations)) -
positionAt
Positions a widget next to another widget.Calls
positionAt(widget, Orientation.Vertical, Orientation.AllOrientations) -
positionAt
Positions a widget next to another widget.Calls
positionAt(widget, orientation, Orientation.AllOrientations) -
setLineHeight
Sets the CSS line height for contained text. -
getLineHeight
Returns the CSS line height for contained text. -
setFloatSide
Specifies a CSS float side.This only applies to widgets with a
PositionScheme.StaticgetPositionScheme().This lets the widget float to one of the sides of the parent widget, at the current line. A typical use is to position images within text. Valid values for Side
Side.Left, orSide.Right.This applies to CSS-based layout.
-
getFloatSide
Returns the CSS float side.- See Also:
-
setClearSides
Sets the sides that should be cleared of floats.This pushes the widget down until it is not surrounded by floats at the
sides(which may be a combination ofSide.LeftandSide.Right).This applies to CSS-based layout.
- See Also:
-
setClearSides
Sets the sides that should be cleared of floats. -
getClearSides
Returns the sides that should remain empty.- See Also:
-
setMargin
Sets CSS margins around the widget.Setting margin has the effect of adding a distance between the widget and surrounding widgets. The default margin (with an automatic length) is zero.
Use any combination of
Side.Left,Side.Right,Side.Bottom, orSide.Top.This applies to CSS-based layout.
- See Also:
-
setMargin
Sets CSS margins around the widget. -
setMargin
Sets CSS margins around the widget. -
setMargin
Sets CSS margins around the widget.This is a convenience method for setting margins in pixel units.
- See Also:
-
setMargin
Sets CSS margins around the widget. -
setMargin
public final void setMargin(int pixels) Sets CSS margins around the widget. -
getMargin
Returns a CSS margin set.This applies to CSS-based layout.
- See Also:
-
setHiddenKeepsGeometry
public abstract void setHiddenKeepsGeometry(boolean enabled) Sets whether the widget keeps its geometry when hidden.Normally, a widget that is hidden will no longer occupy space, causing a reflow of sibling widgets. Using this method you may change this behavior to keep an (open) space when hidden.
Note: Currently you can only set this before initial rendering.
- See Also:
-
isHiddenKeepsGeometry
public abstract boolean isHiddenKeepsGeometry()Returns whether the widget keeps its geometry when hidden.- See Also:
-
setHidden
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(). -
setHidden
public final void setHidden(boolean hidden) Hides or shows the widget. -
isHidden
public abstract boolean isHidden()Returns whether the widget is set hidden.A widget that is not hidden may still be not visible when one of its ancestor widgets is hidden. Use
isVisible()to check the visibility of a widget.- See Also:
-
isVisible
public abstract boolean isVisible()Returns whether the widget is visible.A widget is visible if it is not hidden, and none of its ancestors are hidden. This method returns the true visibility, while
isHidden()returns whether a widget has been explicitly hidden.Note that a widget may be at the same time not hidden, and not visible, in case one of its ancestors was hidden.
- See Also:
-
setDisabled
public abstract void setDisabled(boolean disabled) Sets whether the widget is disabled.The widget can be set to being disabled, or enabled. This state will also be propagated to all its descendants. Those descendants will only be "visually" made disabled, their actual
isDisabled()state will remain unaltered. All descendants will be assigned the disabled styleclass, which is dependent on the used Theme.The
isDisabled()check will thus only returntruein case setDisabled(true) has been called on the widget before. If the anscestor of a widget has been marked setDisabled(true), the widget'sisDisabled()state will remainfalse.To check if a widget has been passively disabled, by one of its anscestors, use
isEnabled().Typically, a disabled form widget will not allow changing the value, and disabled widgets will not react to mouse click events.
- See Also:
-
isDisabled
public abstract boolean isDisabled()Returns whether the widget is set disabled.This method will return
trueif, and only if, it has been marked setDisabled(true) explicitly. It can still inherit the disabled state from one of its anscestors.- See Also:
-
isEnabled
public abstract boolean isEnabled()Returns whether the widget is enabled.A widget is enabled if it is not disabled, and none of its ancestors are disabled. This method returns whether the widget is rendered as enabled, while
isDisabled()returns whether a widget has been explicitly disabled.Note that a widget may be at the same time not enabled, and not disabled, in case one of its ancestors was disabled.
- See Also:
-
setPopup
public abstract void setPopup(boolean popup) Lets the widget overlay over other sibling widgets.A widget that
isPopup()will be rendered on top of any other sibling widget contained within the same parent (including other popup widgets previously added to the container).This will only have an effect when the widgetis either
PositionScheme.AbsoluteorPositionScheme.FixedgetPositionScheme().This applies to CSS-based layout, and configures the z-index property.
-
isPopup
public abstract boolean isPopup()Returns whether the widget is overlayed.This applies to CSS-based layout.
- See Also:
-
setInline
public abstract void setInline(boolean inlined) Sets whether the widget is displayed inline or as a block.This option changes whether this widget must be rendered in line with sibling widgets wrapping at the right edge of the parent container (like text), or whether this widget must be rendered as a rectangular block that stacks vertically with sibling widgets (unless a CSS float property is applied). Depending on the widget type, the default value is inline (such as for example for
WText, orWPushButton), or block (such as for example for aWContainerWidget).This applies to CSS-based layout.
-
isInline
public abstract boolean isInline()Returns whether the widget is displayed inline or as block.- See Also:
-
setDecorationStyle
Sets a CSS decoration style.This copies the style over its current
getDecorationStyle() -
getDecorationStyle
Returns the decoration style of this widget.This groups all decorative aspects of the widget, which do not affect the widget layout (except for the border properties which may behave like extra margin around the widget).
When a decoration style has not been previously set, it returns a default decoration style object.
- See Also:
-
setStyleClass
Sets (one or more) CSS style classes.You may set one or more space separated style classes. CSS style class works in conjunction with style sheet, and provides a flexible way to provide many widgets the same markup.
Setting an empty string removes the style class(es).
- See Also:
-
getStyleClass
Returns the CSS style class.- See Also:
-
addStyleClass
Adds a CSS style class.When
force=true, a JavaScript call will be used to add the style class to the DOM element (if JavaScript is available). This may be necessary when client-side JavaScript manipulates the same style class.The
styleClassshould be a single class (although multiple classes will work for the common case that the additional style classes are all not yet present on the element. -
addStyleClass
Adds a CSS style class. -
removeStyleClass
Removes a CSS style class.When
force=true, a JavaScript call will be used to remove the style class from the DOM element (if JavaScript is available). This may be necessary when client-side JavaScript manipulates the same style class.The
styleClassshould be a single class -
removeStyleClass
Removes a CSS style class. -
toggleStyleClass
Toggles a CSS style class. -
toggleStyleClass
Toggles a CSS style class. -
hasStyleClass
Returns whether the widget has a style class. -
setVerticalAlignment
Sets the vertical alignment.This only applies to inline widgets, and determines how to position itself on the current line, with respect to sibling inline widgets.
This applies to CSS-based layout.
-
setVerticalAlignment
Sets the vertical alignment. -
getVerticalAlignment
Returns the vertical alignment.This applies to CSS-based layout.
- See Also:
-
getVerticalAlignmentLength
Returns the fixed vertical alignment that was set.This applies to CSS-based layout.
- See Also:
-
setToolTip
Sets a tooltip.The tooltip is displayed when the cursor hovers over the widget.
When
textFormatisTextFormat.XHTML, the tooltip may contain any valid XHTML snippet. The tooltip will then be rendered using JavaScript.Note: This will set deferred tooltip to false.
-
setToolTip
Sets a tooltip. -
getToolTip
Returns the tooltip. -
setDeferredToolTip
Enable deferred tooltip.You may override
getToolTip()to read data only when the user hovers over the widget.When
textFormatisTextFormat.XHTML, the tooltip may contain any valid XHTML snippet. The tooltip will then be rendered using JavaScript.Note: To change existing toolTip call
setDeferredToolTip()again.- See Also:
-
setDeferredToolTip
public final void setDeferredToolTip(boolean enable) Enable deferred tooltip. -
refresh
public void refresh()Refresh the widget.The refresh method is invoked when the locale is changed using
WApplication#setLocale()or when the user hit the refresh button.The widget must actualize its contents in response.
Note: This does not rerender the widget! Calling
refresh()usually does not have any effect (unless you've reimplementedrefresh()to attach to it an effect). -
getJsRef
Returns a JavaScript expression to the corresponding DOM node.You may want to use this in conjunction with
JSlotordoJavaScript()in custom JavaScript code.- See Also:
-
setAttributeValue
Sets an attribute value.Sets the value for an HTML attribute.
This is only useful for HTML features that are not supported directly in JWt (and beware that browsers have non-consistent support for many more exotic HTML features).
- See Also:
-
getAttributeValue
Returns an attribute value.- See Also:
-
setJavaScriptMember
Sets a JavaScript member.This binds a JavaScript member, which is set as a JavaScript property to the DOM object that implements this widget. The value may be any JavaScript expression, including a function.
Members that start with
"wt"are reserved for internal use. You may define a member"wtResize(self, width, height)"method if your widget needs active layout management. If defined, this method will be used by layout managers and when doingresize()to set the size of the widget, instead of setting the CSS width and height properties. -
getJavaScriptMember
Returns the value of a JavaScript member.- See Also:
-
callJavaScriptMember
Calls a JavaScript member.This calls a JavaScript member.
- See Also:
-
tr
Short hand forWString#tr()Creates a localized string with the given key.
-
load
public abstract void load()Loads content just before the widget is used.This function is called when a widget is inserted in the widget hierarchy. Widgets that get inserted in the widget hierarchy will be rendered. Visible widgets are rendered immediately, and invisible widgets in the back-ground (or not for a plain HTML session). This method is called when the widget is directly or indirectly inserted into the widget tree.
The default implementation simply propagates the load signal to its children. You may want to override this method to delay loading of resource-intensive contents.
During the life-time of a widget, this method may be called multiple times, so you should make sure that you do a deferred initialization only once.
-
isLoaded
public abstract boolean isLoaded()Returns whether this widget has been loaded.- See Also:
-
setCanReceiveFocus
public abstract void setCanReceiveFocus(boolean enabled) Sets whether the widget can receive focus.By default, only form widgets (descendants of
WFormWidget), anchors (WAnchor) and buttons (WPushButton) can receive focus.Any other widget can be configured to receive focus however.
-
isCanReceiveFocus
public abstract boolean isCanReceiveFocus()Returns whether the widget can receive focus.- See Also:
-
setFocus
public void setFocus()Sets focus.This only has an effect for a widget which can receive focus, and is equivalent to setFocus(true).
- See Also:
-
setFocus
public abstract void setFocus(boolean focus) Sets focus.When using
focus=false, you can undo a previoussetFocus()call. -
isSetFirstFocus
public abstract boolean isSetFirstFocus()Set focus on the widget's first descendant.Set focus on the widget itself, or on a first descendant which can receive focus.
Returns whether focus could be set.
-
hasFocus
public abstract boolean hasFocus()Returns whether the widget currently has the focus. -
setTabIndex
public abstract void setTabIndex(int index) Sets the tab index.For widgets that receive focus (
isCanReceiveFocus()), focus is passed on to the next widget in the tabbing chain based on their tab index. When the user navigates through form widgets using the keyboard, widgets receive focus starting from the element with the lowest tab index to elements with the highest tab index.Widgets with a same tab index will receive focus in the same order as they are inserted in the widget tree.
The default tab index is 0 (for a widget that can receive focus).
-
getTabIndex
public abstract int getTabIndex()Returns the tab index.- See Also:
-
acceptDrops
Sets a mime type to be accepted for dropping.You may specify a style class that is applied to the widget when the specified mimetype hovers on top of it.
- See Also:
-
acceptDrops
Sets a mime type to be accepted for dropping. -
stopAcceptDrops
Indicates that a mime type is no longer accepted for dropping.- See Also:
-
setId
Sets the CSS Id.Sets a custom Id. Note that the Id must be unique across the whole widget tree, can only be set right after construction and cannot be changed. This is mostly useful for in tests using a test plan that manipulates DOM elements by Id.
By default, auto-generated id's are used.
Note: An id must start with a letter ([A-Za-z]), followed by one or more letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Warning: We recommend that you leave the id of a widget unchanged. JWt uses the id to identify widgets in the JavaScript it generates, and this can often leads to bugs. If you do change the id, only change the id right after widget construction. However, usually there's a more preferable alternative, like setting the object name (
WObject#setObjectName()), or adding style classes (addStyleClass()).- See Also:
-
find
Finds a descendent widget by name.- See Also:
-
findById
Finds a descendent widget by id. -
htmlText
Streams the (X)HTML representation.Streams the widget as CharEncoding::UTF8-encoded (HTML-compatible) XHTML.
This may be useful as a debugging tool for the web-savvy, or in other rare situations. Usually, you will not deal directly with HTML, and calling this method on a widget that is rendered may interfere with the library keeping track of changes to the widget.
-
setSelectable
public abstract void setSelectable(boolean selectable) Sets as selectable.When a widget is made unselectable, a selection of text (or images) will not be visible (but may still be possible).
By default, the widget inherits this property from its parent, and this property propagates to all children. The top level container (
WApplication.getRoot()) selectable by default. -
doJavaScript
Executes the given JavaScript statements when the widget is rendered or updated.Calling
WApplication#doJavaScript()with JavaScript code that refers to a widget usinggetJsRef(), that is still to be rendered may cause JavaScript errors because the corresponding DOM node does not exist. This happens for example when a widget is created, but not yet inserted in the widget tree.This method guarantees that the JavaScript code is only run when the corresponding DOM node (using
getJsRef()) resolves to a valid DOM object.- See Also:
-
isRendered
public boolean isRendered()Returns whether the widget is rendered.- See Also:
-
createJavaScript
-
hide
public void hide()Hides the widget.- See Also:
-
animateHide
Hides the widget using an animation.To hide the widget, the animation is replayed in reverse.
- See Also:
-
show
public void show()Shows the widget.- See Also:
-
animateShow
Shows the widget using an animation.- See Also:
-
enable
public void enable()Enables the widget.This calls
setDisabled(). -
disable
public void disable()Disable thes widget.This calls
setDisabled(). -
isLayoutSizeAware
public boolean isLayoutSizeAware()Returns whether the widget is layout size aware.- See Also:
-
isScrollVisibilityEnabled
public abstract boolean isScrollVisibilityEnabled()Returns whether scroll visibility detection is enabled for this widget.- See Also:
-
setScrollVisibilityEnabled
public abstract void setScrollVisibilityEnabled(boolean enabled) Sets whether scroll visibility detection is enabled for this widget.Disabled by default. When enabled, the client keeps track of whether this widget is currently visible inside of the browser window. A widget is "scroll visible" if it is currently visible according to
isVisible(), and its position is inside of the browser window, with an extra margin determined bygetScrollVisibilityMargin().If scroll visibility changes, the
scrollVisibilityChanged()signal is fired, andisScrollVisible()is updated.This feature can be useful to implement infinite scroll, where a sentinel widget placed at the bottom of the page causes more content to be loaded when it becomes visible, see the
scrollvisibilityexample.This feature can also be used to lazy load widgets when they become visible.
Note: If the widget is "scroll visible" when scroll visibility detection is first enabled, the
scrollVisibilityChanged()signal will be emitted. If it is outside of the browser's viewport when first enabled, thescrollVisibilityChanged()signal will not be emitted.Note: If scroll visibility is enabled, disabled, and then enabled again,
isScrollVisible()may not be correctly updated, andscrollVisibilityChanged()may not be correctly emitted, because then JWt can't properly keep track of the state that the widget is in on the client side. This feature is not intended to be toggled on and off, but rather enabled once and disabled once after that. -
getScrollVisibilityMargin
public abstract int getScrollVisibilityMargin()Returns the margin around the viewport within which the widget is considered visible.- See Also:
-
setScrollVisibilityMargin
public abstract void setScrollVisibilityMargin(int margin) Sets the margin around the viewport within which the widget is considered visible.This causes the widget to be considered "scroll visible" before it is within the viewport. Setting this margin could be useful to trigger the loading of content before it is in view.
-
scrollVisibilityChanged
Signaltriggered when the scroll visibility of this widget changes.The boolean parameter indicates whether the widget is currently scroll visible.
- See Also:
-
isScrollVisible
public abstract boolean isScrollVisible()Returns whether this widget is currently considered scroll visible.isScrollVisible()is initially false.- See Also:
-
setThemeStyleEnabled
public abstract void setThemeStyleEnabled(boolean enabled) Sets whether theme styling for a widget is enabled or disabled.By default all widgets are styled according to the chosen theme. Disabling the theme style could be useful to completely customize the style of the widget outside of the theme.
This function does, however, not always completely remove every style class added by JWt, as some of those are needed in order for the widget to function correctly. Additionally, Bootstrap 5 makes some changes to the default style of some widgets in the browser, like with buttons. These changes are not removed by this function.
Note: This should be changed after the construction but before the rendering of the widget or before the call to
applyThemeStyles()(depending on what happens first). -
isThemeStyleEnabled
public abstract boolean isThemeStyleEnabled()Returns whether this widget is currently styled by the chosen theme.isThemeEnabled() is initially true.
- See Also:
-
scheduleThemeStyleApply
Schedules a theme style to be applied at the next render.This schedules a theme style to be applied at the end of the next rendering of the widget, or when the next
applyThemeStyles()is called (depending on what happens first).- See Also:
-
applyThemeStyles
public void applyThemeStyles()Apply the theme style scheduled.This apllies the theme styles scheduled for the next render of this widget.
Warning:
setThemeStyleEnabled()should not be called after using this method.- See Also:
-
isExposed
-
addJSignal
-
getBaseZIndex
public abstract int getBaseZIndex() -
setLayoutSizeAware
protected void setLayoutSizeAware(boolean aware) Sets the widget to be aware of its size set by a layout manager.When the widget is inserted in a layout manager, it will be resized to fit within the constraints imposed by the layout manager. By default, this done client-side only by setting the CSS height (and if needed, width) properties of the DOM element corresponding to the widget.
A widget may define a JavaScript method,
"wtResize(self, width, height)", to actively manage its client-side width and height, if it wants to react to these client-side size hints in a custom way (seesetJavaScriptMember()).By setting
sizeAwareto true, the widget will propagate the width and height provided by the layout manager to the virtuallayoutSizeChanged()method, so that you may for example change the size of contained children in a particular way (doing a custom, manual, layout).- See Also:
-
layoutSizeChanged
protected void layoutSizeChanged(int width, int height) Virtual method that indicates a size change.This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called.
- See Also:
-
dropEvent
Handles a drop event.Reimplement this method to handle a drop events for mime types you declared to accept using acceptDrops.
The default implementation simply completes the drag and drop operation as if nothing happened.
- See Also:
-
enableAjax
protected abstract void enableAjax()Progresses to an Ajax-enabled widget.This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
- See Also:
-
boxPadding
Returns the widget's built-in padding.This is used by the layout managers to correct for a built-in padding which interferes with setting a widget's width (or height) to 100%.
A layout manager needs to set the width to 100% only for form widgets (
WTextArea,WLineEdit,WComboBox, etc...). Therefore, only for those widgets this needs to return the padding (the default implementation returns 0).For form widgets, the padding depends on the specific browser/platform combination, unless an explicit padding is set for the widget.
When setting an explicit padding for the widget using a style class, you will want to reimplement this method to return this padding in case you want to set the widget inside a layout manager.
- See Also:
-
boxBorder
Returns the widget's built-in border width.This is used by the layout managers to correct for a built-in border which interferes with setting a widget's width (or height) to 100%.
A layout manager needs to set the width to 100% only for form widgets (
WTextArea,WLineEdit,WComboBox, etc...). Therefore, only for those widgets this needs to return the border width (the default implementation returns 0).For form widgets, the border width depends on the specific browser/platform combination, unless an explicit border is set for the widget.
When setting an explicit border for the widget using a style class, you will want to reimplement this method to return this border width, in case you want to set the widget inside a layout manager.
- See Also:
-
propagateSetEnabled
protected abstract void propagateSetEnabled(boolean enabled) Propagates that a widget was enabled or disabled through children.When enabling or disabling a widget, you usually also want to disable contained children. This method is called by
setDisabled()to propagate its state to all children.You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.
-
propagateSetVisible
protected abstract void propagateSetVisible(boolean visible) -
getDropTouch
-
scheduleRender
Schedules rerendering of the widget.This schedules a rendering phase after all events have been processed. This method is used internally whenever a property of a widget has been changed. But you may want to use this if you are deferring actual changes to a widget in response to an event, and instead postpone this until all events have been received.
- See Also:
-
scheduleRender
protected final void scheduleRender(eu.webtoolkit.jwt.RepaintFlag flag, eu.webtoolkit.jwt.RepaintFlag... flags) Schedules rerendering of the widget. -
scheduleRender
protected final void scheduleRender()Schedules rerendering of the widget. -
render
Renders 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.
-
render
Renders the widget. -
needsRerender
public boolean needsRerender() -
addCssRule
-
addCssRule
-
isGlobalWidget
protected boolean isGlobalWidget()
-