Class TableColumnGroup

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponentsOfType<TableColumn>, HasElement, HasEnabled, HasSize, HasStyle, TableColumnSpan, Serializable

@NullMarked @Tag("colgroup") public class TableColumnGroup extends HtmlComponent implements TableColumnSpan, HasComponentsOfType<TableColumn>
Component representing a <colgroup> element ? a group of columns inside a Table, used to apply attributes (most often a class for CSS) to several columns at once. Only a limited subset of CSS applies to column groups: background, border (with border-collapse: collapse), visibility: collapse and width.

Per the WHATWG HTML specification, a <colgroup> is used in one of two modes: either it carries a span attribute and has no children, or it contains zero or more <col> children and has no span attribute. This component enforces that: adding a column to a group that carries a span throws, as does setting a span on a group that already has columns. Call TableColumnSpan.resetSpan() or HasComponentsOfType.removeAll() first to switch a group from one mode to the other. <colgroup> elements must be placed after the optional <caption> and before any <thead>, <tbody>, <tfoot> or <tr>; Table inserts them at the correct position automatically.

Since:
25.3
See Also:
  • Constructor Details

    • TableColumnGroup

      public TableColumnGroup()
      Creates a new empty column group.
    • TableColumnGroup

      public TableColumnGroup(TableColumn... columns)
      Creates a new column group with the given columns appended.
      Parameters:
      columns - the columns to add.
    • TableColumnGroup

      public TableColumnGroup(List<? extends TableColumn> columns)
      Parameters:
      columns - the columns to add.
  • Method Details

    • addColumn

      public TableColumn addColumn()
      Appends a new empty <col> child to this group.
      Returns:
      the new column.
    • addColumn

      public TableColumn addColumn(int span)
      Appends a new <col> child with the given span to this group.
      Parameters:
      span - the number of columns to span.
      Returns:
      the new column.
    • insertColumn

      public TableColumn insertColumn(int position)
      Creates a new empty <col> and inserts it at the given position in this group. This is the counterpart of addColumn(), matching insertRow, insertHeaderCell and insertDataCell elsewhere in the family.
      Parameters:
      position - the position to insert the column at, between 0 and the number of columns in this group.
      Returns:
      the new column.
      Throws:
      IllegalStateException - if this group carries a span, which a <colgroup> may not do alongside <col> children. Call TableColumnSpan.resetSpan() first.
    • getColumns

      public List<TableColumn> getColumns()
      Returns the columns inside this group.
      Returns:
      the list of <col> children.
    • add

      public void add(Collection<TableColumn> columns)
      Description copied from interface: HasComponentsOfType
      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.

      Specified by:
      add in interface HasComponentsOfType<TableColumn>
      Parameters:
      columns - the components to add
    • addComponentAtIndex

      public void addComponentAtIndex(int index, TableColumn column)
      Description copied from interface: HasComponentsOfType
      Adds the given component as a 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 HasComponentsOfType<TableColumn>
      Parameters:
      index - the index, where the component will be added. The index must be non-negative and may not exceed the children count
      column - the component to add, value should not be null
    • addComponentAsFirst

      public void addComponentAsFirst(TableColumn column)
      Description copied from interface: HasComponentsOfType
      Adds the given component as the first child of this component.

      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:
      addComponentAsFirst in interface HasComponentsOfType<TableColumn>
      Parameters:
      column - the component to add, value should not be null
    • replace

      public void replace(TableColumn oldColumn, TableColumn newColumn)
      Description copied from interface: HasComponentsOfType
      Replaces the component in the container with another one without changing position. This method replaces a component with another one is such a 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 both components 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 HasComponentsOfType<TableColumn>
      Parameters:
      oldColumn - 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
      newColumn - the new component to be replaced. Can be null, which will make the oldComponent to be removed from the layout without adding any other
    • bindChildren

      public <V extends @Nullable Object, S extends Signal<V>> void bindChildren(Signal<List<S>> list, SerializableFunction<S,TableColumn> childFactory)
      Not supported. The columns of a <colgroup> are structure rather than data, and a binding would attach them straight to the element, bypassing the check that keeps span and <col> children mutually exclusive. Bind the rows of a TableBody instead.
      Specified by:
      bindChildren in interface HasComponentsOfType<TableColumn>
      Type Parameters:
      V - the value type of the Signals in the list
      S - the type of the Signals in the list
      Parameters:
      list - list signal to bind to the parent, must not be null
      childFactory - factory to create new component, must not be null
      Throws:
      UnsupportedOperationException - always.
    • setSpan

      public void setSpan(int span)
      Sets the span attribute ? how many consecutive columns this element covers. The default is 1. Use it to apply the same styling or attributes across a range of columns without writing one element per column.

      A <colgroup> carrying a span may not also have <col> children, so this refuses a group that already has some.

      Specified by:
      setSpan in interface TableColumnSpan
      Parameters:
      span - a positive integer.
      Throws:
      IllegalStateException - if this group has <col> children. Call HasComponentsOfType.removeAll() first.