Class HorizontalLayout

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.orderedlayout.HorizontalLayout
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.ClickNotifier<HorizontalLayout>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasOrderedComponents, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, FlexComponent, ThemableLayout, Serializable

@Tag("vaadin-horizontal-layout") @NpmPackage(value="@vaadin/horizontal-layout", version="25.0.0-alpha19") @JsModule("@vaadin/horizontal-layout/src/vaadin-horizontal-layout.js") public class HorizontalLayout extends com.vaadin.flow.component.Component implements ThemableLayout, FlexComponent, com.vaadin.flow.component.ClickNotifier<HorizontalLayout>
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:
  • Constructor Details

    • HorizontalLayout

      public HorizontalLayout()
      Constructs an empty layout with spacing on by default.
    • HorizontalLayout

      public HorizontalLayout(com.vaadin.flow.component.Component... children)
      Convenience constructor to create a layout with the children already inside it.
      Parameters:
      children - the items to add to this layout
      See Also:
    • HorizontalLayout

      public HorizontalLayout(FlexComponent.JustifyContentMode justifyContentMode, com.vaadin.flow.component.Component... children)
      Convenience constructor to create a layout with the children and specified justifyContentMode.
      Parameters:
      justifyContentMode - the justifyContentMode
      children - the items to add to this layout
      See Also:
    • HorizontalLayout

      public HorizontalLayout(FlexComponent.Alignment alignment, com.vaadin.flow.component.Component... children)
      Convenience constructor to create a layout with the children and specified vertical alignment.
      Parameters:
      alignment - the vertical alignment
      children - the items to add to this layout
      See 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 interface ThemableLayout
      Parameters:
      spacing - adds spacing theme setting if true or removes it if false
    • setVerticalComponentAlignment

      public void setVerticalComponentAlignment(FlexComponent.Alignment alignment, com.vaadin.flow.component.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...) method

      Parameters:
      alignment - the individual alignment for the children components. Setting null will reset the alignment to its default
      componentsToAlign - The components to which the individual alignment should be set
      See Also:
    • getVerticalComponentAlignment

      public FlexComponent.Alignment getVerticalComponentAlignment(com.vaadin.flow.component.Component component)
      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 read
      Returns:
      the alignment of the component, never null
      See Also:
    • setDefaultVerticalComponentAlignment

      public void setDefaultVerticalComponentAlignment(FlexComponent.Alignment alignment)
      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. Setting null will reset the alignment to its default
      See Also:
    • getDefaultVerticalComponentAlignment

      public FlexComponent.Alignment 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

      public void setAlignItems(FlexComponent.Alignment alignment)
      Specified by:
      setAlignItems in interface FlexComponent
      Parameters:
      alignment - the alignment to apply to the components. Setting null will reset the alignment to its default
      See Also:
    • getAlignItems

      public FlexComponent.Alignment getAlignItems()
      Specified by:
      getAlignItems in interface FlexComponent
      Returns:
      the general alignment used by the layout, never null
    • setAlignSelf

      public void setAlignSelf(FlexComponent.Alignment alignment, com.vaadin.flow.component.HasElement... components)
      Specified by:
      setAlignSelf in interface FlexComponent
      Parameters:
      alignment - the individual alignment for the children components. Setting null will reset the alignment to its default
      components - The components to which the individual alignment should be set
      See Also:
    • getAlignSelf

      public FlexComponent.Alignment getAlignSelf(com.vaadin.flow.component.HasElement component)
      Specified by:
      getAlignSelf in interface FlexComponent
      Parameters:
      component - The component which individual layout should be read
      Returns:
      the alignment of the component, never null
      See Also:
    • addAndExpand

      public void addAndExpand(com.vaadin.flow.component.Component... components)
      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, not null
    • replace

      public void replace(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent)
      Specified by:
      replace in interface FlexComponent
      Specified by:
      replace in interface com.vaadin.flow.component.HasOrderedComponents
    • add

      public void add(Collection<com.vaadin.flow.component.Component> components)

      This method only adds components to the start slot.

      Specified by:
      add in interface com.vaadin.flow.component.HasComponents
    • add

      public void add(com.vaadin.flow.component.Component... components)

      This method only adds components to the start slot.

      Specified by:
      add in interface com.vaadin.flow.component.HasComponents
    • addComponentAtIndex

      public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component)
      Specified by:
      addComponentAtIndex in interface com.vaadin.flow.component.HasComponents
    • addToStart

      public void addToStart(com.vaadin.flow.component.Component... components)
      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

      public void addToStart(Collection<com.vaadin.flow.component.Component> components)
      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

      public void addToMiddle(com.vaadin.flow.component.Component... components)
      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

      public void addToMiddle(Collection<com.vaadin.flow.component.Component> components)
      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

      public void addToEnd(com.vaadin.flow.component.Component... components)
      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

      public void addToEnd(Collection<com.vaadin.flow.component.Component> components)
      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.