Class HorizontalLayout

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

@Tag("vaadin-horizontal-layout") @NpmPackage(value="@vaadin/horizontal-layout", version="25.0.0-alpha16") @JsModule("@vaadin/horizontal-layout/src/vaadin-horizontal-layout.js") public class HorizontalLayout extends Component implements ThemableLayout, FlexComponent, 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

  • 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, 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(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, 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(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(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(Component oldComponent, Component newComponent)
      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 interface FlexComponent
      Specified by:
      replace in interface HasOrderedComponents
      Parameters:
      oldComponent - the old component that will be replaced. Can be null, which will make the newComponent to be added to the layout without replacing any other
      newComponent - the new component to be replaced. Can be null, which will make the oldComponent to be removed from the layout without adding any other
    • add

      public void add(Collection<Component> components)
      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 interface HasComponents
      Parameters:
      components - the components to add
    • add

      public void add(Component... components)
      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 interface HasComponents
      Parameters:
      components - the components to add
    • addComponentAtIndex

      public void addComponentAtIndex(int index, Component component)
      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 interface HasComponents
      Parameters:
      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count
      component - the component to add, value should not be null
    • addToStart

      public void addToStart(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<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(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<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(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<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.