Class AbstractSingleComponentContainer

    • Constructor Detail

      • AbstractSingleComponentContainer

        public AbstractSingleComponentContainer()
    • Method Detail

      • iterator

        public java.util.Iterator<com.vaadin.flow.component.Component> iterator()
        Description copied from interface: HasComponents
        Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.

        The iterator is typically unmodifiable, and calls to Iterator.remove() throw an exception.

        Specified by:
        iterator in interface HasComponents
        Specified by:
        iterator in interface java.lang.Iterable<com.vaadin.flow.component.Component>
        Returns:
        the component iterator.
      • fireComponentAttachEvent

        protected void fireComponentAttachEvent​(com.vaadin.flow.component.Component component)
        Fires the component attached event. This is called by the setContent(Component) method after the component has been set as the content.
        Parameters:
        component - the component that has been added to this container.
      • fireComponentDetachEvent

        protected void fireComponentDetachEvent​(com.vaadin.flow.component.Component component)
        Fires the component detached event. This is called by the setContent(Component) method after the content component has been replaced by other content.
        Parameters:
        component - the component that has been removed from this container.
      • setContent

        public void setContent​(com.vaadin.flow.component.Component content)
        Sets the content of this container. The content is a component that serves as the outermost item of the visual contents.

        The content must always be set, either with a constructor parameter or by calling this method.

        Previous versions of Vaadin used a VerticalLayout with margins enabled as the default content but that is no longer the case.

        Specified by:
        setContent in interface SingleComponentContainer
        Parameters:
        content - a component (typically a layout) to use as content
      • setContentWrapper

        protected void setContentWrapper​(com.vaadin.flow.dom.Element wrapper)
        Sets the element that will be used as the content wrapper.

        By default, the content component defined through setContent(Component) is attached as a direct child of AbstractSingleComponentContainer. That's sometimes not the desired behavior if, for instance, the container wants to define a different slot on which the content will be attached to.

        Note that it might have a side effect where Component.getParent() from the content component returns the wrapper instead of the AbstractSingleComponentContainer instance. To avoid this, the Element API can be used to create the element and ComponentUtil.componentFromElement(Element, Class, boolean) to get the component passing false to the mapComponent property, so it won't map the component to the element. Or use the ElementFactory methods.

        The wrapper can only be set once and if no content is already set to the container.

        Parameters:
        wrapper - the wrapper element to be used to attach the content to
      • getContentWrapper

        protected com.vaadin.flow.dom.Element getContentWrapper()
        Get the wrapper to be used as parent of the content element. If no wrapper is set, this.getElement() is returned.
        Returns:
        the wrapper or this.getElement() element.
      • removeFromParent

        public static void removeFromParent​(com.vaadin.flow.component.Component content)
                                     throws java.lang.IllegalArgumentException
        Utility method for removing a component from its parent (if possible).
        Parameters:
        content - component to remove
        Throws:
        java.lang.IllegalArgumentException
      • setHeight

        public void setHeight​(float height,
                              Sizeable.Unit unit)
        Description copied from interface: Sizeable
        Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
        Specified by:
        setHeight in interface Sizeable
        Overrides:
        setHeight in class AbstractComponent
        Parameters:
        height - the height of the object.
        unit - the unit used for the width.
      • setWidth

        public void setWidth​(float width,
                             Sizeable.Unit unit)
        Description copied from interface: Sizeable
        Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
        Specified by:
        setWidth in interface Sizeable
        Overrides:
        setWidth in class AbstractComponent
        Parameters:
        width - the width of the object.
        unit - the unit used for the width.