com.vaadin.flow.component.orderedlayout.
Class HorizontalLayout
All Implemented Interfaces:
AttachNotifier
, ClickNotifier<HorizontalLayout>
, DetachNotifier
, HasComponents
, HasElement
, HasEnabled
, HasOrderedComponents
, HasSize
, HasStyle
, FlexComponent
, ThemableLayout
, Serializable
Horizontal Layout places components side-by-side in a row. By default, it has undefined width and height, meaning its size is determined by the components it contains.
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.orderedlayout.FlexComponent
FlexComponent.Alignment, FlexComponent.JustifyContentMode
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty layout with spacing on by default.
HorizontalLayout
(Component... children) Convenience constructor to create a layout with the children already inside it.
HorizontalLayout
(FlexComponent.Alignment alignment, Component... children) Convenience constructor to create a layout with the children and specified vertical alignment.
HorizontalLayout
(FlexComponent.JustifyContentMode justifyContentMode, Component... children) Convenience constructor to create a layout with the children and specified justifyContentMode.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given components as children of this component.
void
add
(Collection<Component> components) Adds the given components as children of this component.
void
addAndExpand
(Component... components) Adds the given components to this layout and sets them as expanded.
void
addComponentAtIndex
(int index, Component component) Adds the given component as child of this component at the specific index.
void
Adds the components to the middle slot of this layout.
void
addToEnd
(Collection<Component> components) Adds the components to the end slot of this layout.
void
addToMiddle
(Component... components) Adds the components to the middle slot of this layout.
void
addToMiddle
(Collection<Component> components) Adds the components to the middle slot of this layout.
void
addToStart
(Component... components) Adds the components to the start slot of this layout.
void
addToStart
(Collection<Component> components) Adds the components to the start slot of this layout.
This is the same as
getDefaultVerticalComponentAlignment()
.getAlignSelf
(HasElement component) This is the same as
getVerticalComponentAlignment(Component)
.Gets the default vertical alignment used by all components without individual alignments inside the layout.
getVerticalComponentAlignment
(Component component) Gets the individual vertical alignment of a given component.
void
Replaces the component in the container with another one without changing position.
void
setAlignItems
(FlexComponent.Alignment alignment) This is the same as
setDefaultVerticalComponentAlignment(Alignment)
.void
setAlignSelf
(FlexComponent.Alignment alignment, HasElement... components) This is the same as
setVerticalComponentAlignment(Alignment, Component...)
.void
Sets the default vertical alignment to be used by all components without individual alignments inside the layout.
void
setSpacing
(boolean spacing) Toggles
spacing
theme setting for the element.void
setVerticalComponentAlignment
(FlexComponent.Alignment alignment, Component... componentsToAlign) Sets a vertical alignment for individual components inside the layout.
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.orderedlayout.FlexComponent
expand, getFlexGrow, getFlexShrink, getJustifyContentMode, setFlexGrow, setFlexShrink, setJustifyContentMode
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, addComponentAsFirst, remove, remove, removeAll
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasOrderedComponents
getChildren, getComponentAt, getComponentCount, indexOf
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
Methods inherited from interface com.vaadin.flow.component.orderedlayout.ThemableLayout
getBoxSizing, getSpacing, getThemeList, isMargin, isPadding, isSpacing, isWrap, setBoxSizing, setMargin, setPadding, setSpacing, setSpacing, setWrap
-
Constructor Details
-
HorizontalLayout
public HorizontalLayout()Constructs an empty layout with spacing on by default.
-
HorizontalLayout
Convenience constructor to create a layout with the children already inside it.
Parameters:
children
- the items to add to this layoutSee Also:
-
HorizontalLayout
Convenience constructor to create a layout with the children and specified justifyContentMode.
Parameters:
justifyContentMode
- the justifyContentModechildren
- the items to add to this layoutSee Also:
-
HorizontalLayout
Convenience constructor to create a layout with the children and specified vertical alignment.
Parameters:
alignment
- the vertical alignmentchildren
- the items to add to this layoutSee Also:
-
-
Method Details
-
setSpacing
public void setSpacing(boolean spacing) Toggles
spacing
theme setting for the element. If a theme supports this attribute, it will apply or remove spacing to the element.This method adds medium spacing to the component theme, to set other options, use
ThemableLayout.getThemeList()
. List of options possible:- spacing-xs
- spacing-s
- spacing
- spacing-l
- spacing-xl
Spacing is enabled by default for horizontal layout.
Specified by:
setSpacing
in interfaceThemableLayout
Parameters:
spacing
- addsspacing
theme setting iftrue
or removes it iffalse
-
setVerticalComponentAlignment
public void setVerticalComponentAlignment(FlexComponent.Alignment alignment, Component... componentsToAlign) Sets a vertical alignment for individual components inside the layout. This individual alignment for the component overrides any alignment set at the
setDefaultVerticalComponentAlignment(Alignment)
.It effectively sets the
"alignSelf"
style value.The default alignment for individual components is
FlexComponent.Alignment.AUTO
.It's the same as the
setAlignSelf(Alignment, HasElement...)
methodParameters:
alignment
- the individual alignment for the children components. Settingnull
will reset the alignment to its defaultcomponentsToAlign
- The components to which the individual alignment should be setSee Also:
-
getVerticalComponentAlignment
Gets the individual vertical alignment of a given component.
The default alignment for individual components is
FlexComponent.Alignment.AUTO
.It's the same as the
getAlignSelf(HasElement)
method.Parameters:
component
- The component which individual layout should be readReturns:
the alignment of the component, never
null
See Also:
-
setDefaultVerticalComponentAlignment
Sets the default vertical alignment to be used by all components without individual alignments inside the layout. Individual components can be aligned by using the
setVerticalComponentAlignment(Alignment, Component...)
method.It effectively sets the
"alignItems"
style value.The default alignment is
FlexComponent.Alignment.STRETCH
.It's the same as the
setAlignItems(Alignment)
method.Parameters:
alignment
- the alignment to apply to the components. Settingnull
will reset the alignment to its defaultSee Also:
-
getDefaultVerticalComponentAlignment
Gets the default vertical alignment used by all components without individual alignments inside the layout.
The default alignment is
FlexComponent.Alignment.STRETCH
.This is the same as the
getAlignItems()
method.Returns:
the general alignment used by the layout, never
null
-
setAlignItems
This is the same as
setDefaultVerticalComponentAlignment(Alignment)
.Specified by:
setAlignItems
in interfaceFlexComponent
Parameters:
alignment
- the alignment to apply to the components. Settingnull
will reset the alignment to its defaultSee Also:
-
getAlignItems
This is the same as
getDefaultVerticalComponentAlignment()
.Specified by:
getAlignItems
in interfaceFlexComponent
Returns:
the general alignment used by the layout, never
null
-
setAlignSelf
This is the same as
setVerticalComponentAlignment(Alignment, Component...)
.Specified by:
setAlignSelf
in interfaceFlexComponent
Parameters:
alignment
- the individual alignment for the children components. Settingnull
will reset the alignment to its defaultcomponents
- The components to which the individual alignment should be setSee Also:
-
getAlignSelf
This is the same as
getVerticalComponentAlignment(Component)
.Specified by:
getAlignSelf
in interfaceFlexComponent
Parameters:
component
- The component which individual layout should be readReturns:
the alignment of the component, never
null
See Also:
-
addAndExpand
Adds the given components to this layout and sets them as expanded. The flex-grow of all added child components are set to 1 so that the expansion will be effective. The width of this layout is also set to 100%.
Parameters:
components
- the components to set, notnull
-
replace
Description copied from interface:
HasOrderedComponents
Replaces the component in the container with another one without changing position. This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
Specified by:
replace
in interfaceFlexComponent
Specified by:
replace
in interfaceHasOrderedComponents
Parameters:
oldComponent
- the old component that will be replaced. Can benull
, which will make the newComponent to be added to the layout without replacing any othernewComponent
- the new component to be replaced. Can benull
, which will make the oldComponent to be removed from the layout without adding any other -
add
Adds the given components as children of this component.
In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.
This method only adds components to the start slot.
Specified by:
add
in interfaceHasComponents
Parameters:
components
- the components to add -
add
Adds the given components as children of this component.
In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.
This method only adds components to the start slot.
Specified by:
add
in interfaceHasComponents
Parameters:
components
- the components to add -
addComponentAtIndex
Description copied from interface:
HasComponents
Adds the given component as child of this component at the specific index.
In case the specified component has already been added to another parent, it will be removed from there and added to this one.
Specified by:
addComponentAtIndex
in interfaceHasComponents
Parameters:
index
- the index, where the component will be added. The index must be non-negative and may not exceed the children countcomponent
- the component to add, value should not be null -
addToStart
Adds the components to the start slot of this layout.
Parameters:
components
- Components to add to the start slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null. -
addToStart
Adds the components to the start slot of this layout.
Parameters:
components
- Components to add to the start slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null. -
addToMiddle
Adds the components to the middle slot of this layout.
Parameters:
components
- Components to add to the middle slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null. -
addToMiddle
Adds the components to the middle slot of this layout.
Parameters:
components
- Components to add to the middle slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null. -
addToEnd
Adds the components to the middle slot of this layout.
Parameters:
components
- Components to add to the middle slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null. -
addToEnd
Adds the components to the end slot of this layout.
Parameters:
components
- Components to add to the middle slot.Throws:
NullPointerException
- if any of the components is null or if the components array is null.
-