|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WWidget
eu.webtoolkit.jwt.WWebWidget
eu.webtoolkit.jwt.WInteractWidget
eu.webtoolkit.jwt.WContainerWidget
public class WContainerWidget
A widget that holds and manages child widgets.
A WContainerWidget acts as a container for child widgets. Child widgets may be added directly to the container or using a layout manager.
Use addWidget() or pass
the container as constructor argument to a widget to directly add children to
the container, without using a layout manager. In that case, CSS-based layout
is used, and the resulting display is determined by properties of the
children and the container. By default, a WContainerWidget is displayed as a
block and manages its children
within a rectangle. Inline child widgets are layed out in lines, wrapping
around as needed, while block child widgets are stacked vertically. The
container may add padding at the container edges using
setPadding(), and provide alignment of contents using
setContentAlignment(). A container is rendered by default using a HTML
div tag, but this may be changed to an HTML ul or
ol tag to make use of other CSS layout techniques, using
setList(). In
addition, specializations of this class as implemented by WAnchor,
WGroupBox, WStackedWidget and WTableCell provide
other alternative rendering of the container.
When setting the WContainerWidget inline the container only acts as a conceptual container, offering a common
style to its children. Inline children are still layed out inline within the
flow of the parent container of this container, as if they were inserted
directly into that parent container. Block children are then not allowed
(according to the HTML specification).
To use a layout manager instead of CSS-based layout, use
setLayout() or pass the
container as constructor argument to a layout manager. In that case you
should not define any padding for the container, and widgets and nested
layout managers must be added to the layout manager, instead of to the
container directly.
Usage example:
// Example 1:
// Instantiate a container widget and add some children whose layout
// is governed based on HTML/CSS rules.
WContainerWidget container1 = new WContainerWidget();
container1.addWidget(new WText("Some text"));
container1.addWidget(new WImage("images/img.png"));
WContainerWidget child3 = new WContainerWidget(container1);
// Example 2:
// Instantiate a container widget which uses a layout manager
WContainerWidget container2 = new WContainerWidget();
// give the container a fixed height
container2.resize(WLength.Auto, new WLength(600));
WVBoxLayout layout = new WVBoxLayout();
layout.addWidget(new WText("Some text"));
layout.addWidget(new WImage("images/img.png"));
container2.setLayout(layout); // set the layout to the container.
When using a layout manager, you need to carefully consider the alignment of
the layout manager with respect to the container: when the container's
height is unconstrained (not specified explicitly using
WWebWidget#resize()
or a style class, and the container is not included in a layout manager), you
should pass AlignTop to setLayout().
Depending on its configuration and usage, the widget corresponds to the following HTML tags:
<div> tag.<span>.<ul>.<ol>.isList(), the widget corresponds to a
<li>.This widget does not provide styling, and can be styled using inline or external CSS as appropriate.
| Nested Class Summary | |
|---|---|
static class |
WContainerWidget.Overflow
How to handle overflow of inner content. |
| Constructor Summary | |
|---|---|
WContainerWidget()
Creates a container with optional parent. |
|
WContainerWidget(WContainerWidget parent)
Creates a container with optional parent. |
|
| Method Summary | |
|---|---|
void |
addWidget(WWidget widget)
Adds a child widget to this container. |
void |
clear()
Removes and deletes all child widgets. |
java.util.EnumSet<AlignmentFlag> |
getContentAlignment()
Returns the alignment of children. |
int |
getCount()
Returns the number of widgets in this container. |
int |
getIndexOf(WWidget widget)
Returns the index of a widget. |
WLayout |
getLayout()
Returns the layout manager that was set for the container. |
WLength |
getPadding(Side side)
Returns the padding set for the widget. |
WWidget |
getWidget(int index)
Returns the widget at index. |
void |
insertBefore(WWidget widget,
WWidget before)
Inserts a child widget in this container, before another widget. |
void |
insertWidget(int index,
WWidget widget)
Inserts a child widget in this container at given index. |
boolean |
isList()
Returns if this container is rendered as a List. |
boolean |
isOrderedList()
Returns if this container is rendered as an Ordered List. |
boolean |
isUnorderedList()
Returns if this container is rendered as an Unordered List. |
void |
remove()
Destructor. |
void |
removeWidget(WWidget widget)
Removes a child widget from this container. |
EventSignal1<WScrollEvent> |
scrolled()
Event signal emitted when scrolling in the widget. |
void |
setContentAlignment(AlignmentFlag alignmen,
AlignmentFlag... alignment)
Specifies how child widgets must be aligned within the container. |
void |
setContentAlignment(java.util.EnumSet<AlignmentFlag> alignment)
Specifies how child widgets must be aligned within the container. |
void |
setLayout(WLayout layout)
Sets a layout manager for the container. |
void |
setLayout(WLayout layout,
AlignmentFlag alignmen,
AlignmentFlag... alignment)
Sets a layout manager for the container. |
void |
setLayout(WLayout layout,
java.util.EnumSet<AlignmentFlag> alignment)
Sets a layout manager for the container. |
void |
setList(boolean list)
Renders the container as an HTML list. |
void |
setList(boolean list,
boolean ordered)
Renders the container as an HTML list. |
void |
setOverflow(WContainerWidget.Overflow value)
Sets how overflow of contained children must be handled. |
void |
setOverflow(WContainerWidget.Overflow value,
java.util.EnumSet<Orientation> orientation)
Sets how overflow of contained children must be handled. |
void |
setOverflow(WContainerWidget.Overflow value,
Orientation orientatio,
Orientation... orientation)
Sets how overflow of contained children must be handled. |
void |
setPadding(WLength length)
Sets padding inside the widget. |
void |
setPadding(WLength length,
java.util.EnumSet<Side> sides)
Sets padding inside the widget. |
void |
setPadding(WLength length,
Side side,
Side... sides)
Sets padding inside the widget. |
| Methods inherited from class eu.webtoolkit.jwt.WInteractWidget |
|---|
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, touchEnded, touchMoved, touchStarted |
| Methods inherited from class eu.webtoolkit.jwt.WWidget |
|---|
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, 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 |
|---|
getObjectName, setObjectName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WContainerWidget(WContainerWidget parent)
public WContainerWidget()
Calls this((WContainerWidget)null)
| Method Detail |
|---|
public void remove()
remove in class WInteractWidgetremoveWidget(WWidget widget)public void setLayout(WLayout layout)
Note that you can nest layout managers inside each other, to create a complex layout hierarchy.
If a previous layout manager was already set, it is first deleted. In that case, you will need to make sure that you either readd all widgets that were part of the previous layout to the new layout, or delete them, to avoid memory leaks.
The layout manager arranges children in the entire width and height of
the container. This is equivalent to
setLayout(layout, AlignJustify)
getLayout(),
setLayout(WLayout layout, EnumSet alignment)
public void setLayout(WLayout layout,
java.util.EnumSet<AlignmentFlag> alignment)
The alignment argument determines how the layout is aligned
inside the container. By default, the layout manager arranges children
over the entire width and height of the container, corresponding to a
value of AlignJustify. This requires that the container has a specified
height (either because it is managed by another layout manager, is the
root container widget, or has a height set).
In general, alignment is the logical OR of a horizontal and
a vertical flag:
AlignmentFlag.AlignLeft, AlignmentFlag.AlignCenter,
AlignmentFlag.AlignRight, or AlignmentFlag.AlignJustify.AlignmentFlag.AlignTop.
When using a horizontal alingment different from
AlignmentFlag.AlignJustify, and a vertical alignment different
from '0', the widget is sized in that direction to fit the
contents, instead of the contents being adjusted to the widget size. This
is useful when the container does not have a specific size in that
direction and when the layout manager does not contain any widgets that
wish to consume all remaining space in that direction.
Only a single layout manager may be set. If you want to replace the
current layout manager, you have to erase all contents first using
clear(), which also deletes the layout
manager.
Note that you can nest layout managers inside each other, to create a complex layout hierarchy.
The widget will take ownership of layout.
getLayout()
public final void setLayout(WLayout layout,
AlignmentFlag alignmen,
AlignmentFlag... alignment)
Calls setLayout(layout, EnumSet.of(alignmen, alignment))
public WLayout getLayout()
If no layout manager was previously set using setLayout(WLayout
), 0 is returned.
setLayout(WLayout layout)public void addWidget(WWidget widget)
This is equivalent to passing this container as the parent when constructing the child. The widget is appended to the list of children, and thus also layed-out at the end.
public void insertBefore(WWidget widget,
WWidget before)
The widget is inserted at the place of the before
widget, and subsequent widgets are shifted.
insertWidget(int index, WWidget widget)
public void insertWidget(int index,
WWidget widget)
The widget is inserted at the given index, and
subsequent widgets are shifted.
insertBefore(WWidget widget, WWidget before)public void removeWidget(WWidget widget)
This removes the widget from this container, but does not delete the widget !
public void clear()
This deletes all children that have been added to this container.
If a layout was set, also the layout manager is deleted.
public int getIndexOf(WWidget widget)
public WWidget getWidget(int index)
public int getCount()
public void setContentAlignment(java.util.EnumSet<AlignmentFlag> alignment)
For a WContainerWidget, only specifes the horizontal alignment of
child widgets. Note that there is no way to specify vertical alignment:
children are always pushed to the top of the container.
For a WTableCell, this may also specify the vertical alignment.
The default alignment is (AlignmentFlag.AlignTop |
AlignmentFlag.AlignLeft).
public final void setContentAlignment(AlignmentFlag alignmen,
AlignmentFlag... alignment)
Calls setContentAlignment(EnumSet.of(alignmen, alignment))
public void setPadding(WLength length,
java.util.EnumSet<Side> sides)
Setting padding has the effect of adding distance between the widget children and the border.
public final void setPadding(WLength length,
Side side,
Side... sides)
Calls setPadding(length, EnumSet.of(side, sides))
public final void setPadding(WLength length)
Calls setPadding(length, Side.All)
public WLength getPadding(Side side)
setPadding(WLength length, EnumSet sides)public java.util.EnumSet<AlignmentFlag> getContentAlignment()
setContentAlignment(EnumSet alignment)
public void setOverflow(WContainerWidget.Overflow value,
java.util.EnumSet<Orientation> orientation)
This is an alternative (CSS-ish) way to configure scroll bars on a
container widget, compared to wrapping inside a WScrollArea.
Unlike WScrollArea, horizontal scrolling does not work reliably
when the container widget is inserted in a layout manager: the layout
manager will overflow rather than use scrollbars for this container
widget. A solution then is to use WScrollArea instead.
WScrollArea
public final void setOverflow(WContainerWidget.Overflow value,
Orientation orientatio,
Orientation... orientation)
Calls
setOverflow(value, EnumSet.of(orientatio, orientation))
public final void setOverflow(WContainerWidget.Overflow value)
Calls
setOverflow(value, EnumSet.of (Orientation.Horizontal,
Orientation.Vertical))
public void setList(boolean list,
boolean ordered)
Setting renderList to true will cause the
container to be using an HTML <ul> or
<ol> type, depending on the value of
orderedList. This must be set before the initial render of
the container. When set, any contained WContainerWidget will be
rendered as an HTML <li>. Adding non-WContainerWidget
children results in unspecified behaviour.
Note that CSS default layout rules for <ul> and
<ol> add margin and padding to the container, which
may look odd if you do not use bullets.
By default, a container is rendered using a <div>
element.
isList(),
isOrderedList(),
isUnorderedList()public final void setList(boolean list)
Calls setList(list,
false)
public boolean isList()
setList(boolean list, boolean ordered),
isOrderedList(),
isUnorderedList()public boolean isUnorderedList()
setList(boolean list, boolean ordered),
isList(),
isOrderedList()public boolean isOrderedList()
setList(boolean list, boolean ordered),
isList(),
isUnorderedList()public EventSignal1<WScrollEvent> scrolled()
This event is emitted when the user scrolls in the widget (for setting
the scroll bar policy, see
setOverflow()). The event conveys details such as the new scroll bar
position, the total contents height and the current widget height.
setOverflow(WContainerWidget.Overflow value,
EnumSet orientation)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||