Class CssLayout
- All Implemented Interfaces:
LayoutEvents.LayoutClickNotifier,ClientConnector,FAbstractClientConnector,FSizeable,Sizeable,ComponentContainer,FAbstractComponent,HasComponents,HasComponents.ComponentAttachDetachNotifier,Layout,com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.shared.HasTooltip,Serializable,Iterable<com.vaadin.flow.component.Component>
In comparison to HorizontalLayout and VerticalLayout
- rather similar server side api
- no spacing, alignment or expand ratios
- much simpler DOM that can be styled by skilled web developer
- no abstraction of browser differences (developer must ensure that the result works properly on each browser)
- different kind of handling for relative sizes (that are set from server side) (*)
- noticeably faster rendering time in some situations as we rely more on the browser's rendering engine.
By extending CssLayout one can also inject some css rules straight to child
components using getCss(Component).
(*) Relative sizes (set from server side) are treated bit differently than in other layouts in Vaadin. In cssLayout the size is calculated relatively to CSS layouts content area which is pretty much as in html and css. In other layouts the size of component is calculated relatively to the "slot" given by layout.
Also note that client side framework in Vaadin modifies inline style properties width and height. This happens on each update to component. If one wants to set component sizes with CSS, component must have undefined size on server side (which is not the default for all components) and the size must be defined with class styles - not by directly injecting width and height.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.featurepack.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListenerNested classes/interfaces inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
FAbstractClientConnector.LegacyMethodEventNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
FAbstractComponent.DataKeyNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListenerNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.Layout
Layout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LinkedList<com.vaadin.flow.component.Component> Custom layout slots containing the components.Fields inherited from interface com.vaadin.featurepack.server.Sizeable
SIZE_UNDEFINED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponent(com.vaadin.flow.component.Component c) Add a component into this container.voidaddComponent(com.vaadin.flow.component.Component c, int index) Adds a component into indexed position in this container.voidaddComponentAsFirst(com.vaadin.flow.component.Component c) Adds a component into this container.com.vaadin.flow.shared.RegistrationAdd a click listener to the layout.voidbeforeClientResponse(boolean initial) Called before the response is written to client side.com.vaadin.flow.component.ComponentgetComponent(int index) Returns the component at the given position.intGets the number of contained components.intgetComponentIndex(com.vaadin.flow.component.Component component) Returns the index of the given component.protected StringgetCss(com.vaadin.flow.component.Component c) Returns styles to be applied to given component.Iterator<com.vaadin.flow.component.Component> iterator()Gets the component container iterator for going trough all the components in the container.voidremoveComponent(com.vaadin.flow.component.Component c) Removes the component from this container.voidvoidreplaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Replaces the component in the container with another one without changing position.voidsetLabelComponent(com.vaadin.flow.component.Component labelComponent) Sets the component's label component.Methods inherited from class com.vaadin.featurepack.ui.AbstractComponentContainer
add, addComponentAttachListener, addComponentDetachListener, addComponents, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, remove, removeAll, removeAllComponents, setHeight, setWidthMethods inherited from class com.vaadin.featurepack.ui.AbstractComponent
addClassName, addClassNames, addInternalStyles, doSetHeight, doSetWidth, fireComponentEvent, fireEvent, focus, getClassName, getClassNames, getCustomStyles, getHeight, getHeightUnits, getInternalStyles, getLocale, getStyle, getTooltip, getWidth, getWidthUnits, hasClassName, isOrHasAncestor, isVisible, onEnabledStateChanged, removeClassName, removeClassNames, removeInternalStyles, setClassName, setClassName, setHeight, setHeightFull, setHeightUndefined, setParent, setSizeFull, setSizeUndefined, setTooltipText, setVisible, setWidth, setWidthFull, setWidthUndefinedMethods inherited from class com.vaadin.featurepack.server.AbstractClientConnector
getSession, onAttach, onDetachMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, from, get, getChildren, getElement, getEventBus, getId, getListeners, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.featurepack.ui.ComponentContainer
addComponents, moveComponentsFrom, removeAllComponentsMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, attach, detach, doConnectorOnAttach, doConnectorOnDetach, fireEvent, fireEvent, getAllChildrenIterable, getFListeners, getFlowComponent, getResource, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeListener, removeListener, setResourceMethods inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, addStyleNames, getCaption, getComponentError, getData, getDescription, getFErrorIndicator, getFErrorMessage, getFId, getFParent, getIcon, getIconResource, getPrimaryStyleName, getStyleName, isCaptionAsHtml, isImmediate, isResponsive, notifyParentAboutStyleChanges, removeContextClickListener, removeShortcutListener, removeStyleName, removeStyleNames, setCaption, setCaptionAsHtml, setComponentError, setData, setDescription, setDescription, setIcon, setIcon, setIconResource, setImmediate, setLocale, setPrimaryStyleName, setResponsive, setStyleName, setStyleNameMethods inherited from interface com.vaadin.featurepack.server.FSizeable
getFHeight, getFWidthMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods inherited from interface com.vaadin.featurepack.ui.HasComponents.ComponentAttachDetachNotifier
addComponentAttachListener, addComponentDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, add, addComponentAtIndex, bindChildren, getChildren, getComponentAt, indexOf, remove, remove, removeAll, replaceMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.component.HasStyle
bindClassName, bindClassNamesMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
setTooltipMarkdownMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
components
Custom layout slots containing the components.
-
-
Constructor Details
-
CssLayout
public CssLayout()Constructs an empty CssLayout. -
CssLayout
public CssLayout(com.vaadin.flow.component.Component... children) Constructs a CssLayout with the given components in the given order.- Parameters:
children- Components to add to the container.- See Also:
-
-
Method Details
-
setLabelComponent
public void setLabelComponent(com.vaadin.flow.component.Component labelComponent) Description copied from interface:FAbstractComponentSets the component's label component. Flow components that support caption component usually overrides this.- Specified by:
setLabelComponentin interfaceFAbstractComponent- Parameters:
labelComponent- the new label component for the component.
-
addComponent
public void addComponent(com.vaadin.flow.component.Component c) Add a component into this container. The component is added to the right or below the previous component.- Specified by:
addComponentin interfaceComponentContainer- Overrides:
addComponentin classAbstractComponentContainer- Parameters:
c- the component to be added.
-
addComponentAsFirst
public void addComponentAsFirst(com.vaadin.flow.component.Component c) Adds a component into this container. The component is added to the left or on top of the other components.- Specified by:
addComponentAsFirstin interfacecom.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>- Parameters:
c- the component to be added.
-
addComponent
public void addComponent(com.vaadin.flow.component.Component c, int index) Adds a component into indexed position in this container.- Parameters:
c- the component to be added.index- the index of the component position. The components currently in and after the position are shifted forwards.
-
removeComponent
public void removeComponent(com.vaadin.flow.component.Component c) Removes the component from this container.- Specified by:
removeComponentin interfaceComponentContainer- Overrides:
removeComponentin classAbstractComponentContainer- Parameters:
c- the component to be removed.
-
iterator
Gets the component container iterator for going trough all the components in the container.- Specified by:
iteratorin interfaceHasComponents- Specified by:
iteratorin interfaceIterable<com.vaadin.flow.component.Component>- Overrides:
iteratorin classAbstractComponentContainer- Returns:
- the Iterator of the components inside the container.
-
getComponentCount
public int getComponentCount()Gets the number of contained components. Consistent with the iterator returned byiterator().- Specified by:
getComponentCountin interfaceComponentContainer- Specified by:
getComponentCountin interfacecom.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>- Returns:
- the number of contained components
-
beforeClientResponse
public void beforeClientResponse(boolean initial) Description copied from interface:ClientConnectorCalled before the response is written to client side. Gives the legacy connector an opportunity to set computed/dynamic state values.This is implemented for the legacy components to keep consistent behavior and e.g. legaze size calculations working.
NOTE: the parameter
initialisfalsewhen the component is attached again to a newUIwhenPreserveOnRefreshis used.- Specified by:
beforeClientResponsein interfaceClientConnector- Specified by:
beforeClientResponsein interfaceFAbstractClientConnector- Specified by:
beforeClientResponsein interfaceFAbstractComponent- Overrides:
beforeClientResponsein classAbstractComponent- Parameters:
initial-trueif the client-side connector will be created and initialized after this method has been invoked.falseif there is already an initialized client-side connector.
-
getCss
Returns styles to be applied to given component. Override this method to inject custom style rules to components.Note that styles are injected over previous styles before actual child rendering. Previous styles are not cleared, but overridden.
Note that one most often achieves better code style, by separating styling to theme (with custom theme and
FAbstractComponent.addStyleName(String). With own custom styles it is also very easy to break browser compatibility.- Parameters:
c- the component- Returns:
- CSS rules to be applied to a component
-
replaceComponent
public void replaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Description copied from interface:ComponentContainerReplaces 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:
replaceComponentin interfaceComponentContainer- Parameters:
oldComponent- the old component that will be replaced.newComponent- the new component to be replaced.
-
addLayoutClickListener
public com.vaadin.flow.shared.Registration addLayoutClickListener(LayoutEvents.LayoutClickListener listener) Description copied from interface:LayoutEvents.LayoutClickNotifierAdd a click listener to the layout. The listener is called whenever the user clicks inside the layout. An event is also triggered when the click targets a component inside a nested layout or Panel, provided the targeted component does not prevent the click event from propagating. A caption is not considered part of a component.The child component that was clicked is included in the
LayoutEvents.LayoutClickEvent.- Specified by:
addLayoutClickListenerin interfaceLayoutEvents.LayoutClickNotifier- Parameters:
listener- The listener to add- Returns:
- a registration object for removing the listener
- See Also:
-
removeLayoutClickListener
-
getComponentIndex
public int getComponentIndex(com.vaadin.flow.component.Component component) Returns the index of the given component.- Parameters:
component- The component to look up.- Returns:
- The index of the component or -1 if the component is not a child.
-
getComponent
Returns the component at the given position.- Parameters:
index- The position of the component.- Returns:
- The component at the given index.
- Throws:
IndexOutOfBoundsException- If the index is out of range.
-