Class GroupBox

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class GroupBox extends Container

A titled frame around a group of related controls.

The desktop equivalent of a section header, and the one piece of grouping chrome all three desktop toolkits agree on: NSBox with a title, GtkFrame with a label widget, and WinUI's headered content. On a phone the same grouping is expressed by a gap and a heading, which is why Codename One never had this -- and why a desktop form built out of plain containers reads as one undifferentiated column of controls.

Two UIIDs: GroupBox styles the frame (its border is the box) and GroupBoxTitle styles the caption. A theme that wants the caption to sit in the top edge rather than above it does that with a negative top margin on GroupBoxTitle; nothing here hard-codes a position, because the three platforms disagree about it.

GroupBox appearance = new GroupBox("Appearance");
appearance.add(new CheckBox("Use the system accent colour"))
          .add(new CheckBox("Reduce transparency"));

The content is an ordinary Container, so add, remove and the layout all behave as they would anywhere else -- #getContentPane() is there for the rare caller that wants the inner container itself.

  • Constructor Details

    • GroupBox

      public GroupBox()
      An untitled group whose content stacks vertically.
    • GroupBox

      public GroupBox(String titleText)

      A titled group whose content stacks vertically.

      Parameters
      • titleText: the caption
    • GroupBox

      public GroupBox(String titleText, Layout contentLayout)

      A titled group with a layout of its own.

      Parameters
      • titleText: the caption

      • contentLayout: the layout for the grouped controls

  • Method Details

    • getTitle

      public String getTitle()

      The caption.

      Returns

      the title text, never null

    • setTitle

      public void setTitle(String titleText)

      Sets the caption. Setting it empty removes the caption strip entirely.

      Parameters
      • titleText: the caption
    • getTitleComponent

      public Label getTitleComponent()

      The caption component, for a caller that needs to style or replace its icon.

      Returns

      the title label

    • getContentPane

      public Container getContentPane()

      The container the grouped controls live in.

      Returns

      the content container

    • addComponent

      public void addComponent(Component cmp)
      Description copied from class: Container

      Adds a Component to the Container

      Parameters
      • cmp: the component to be added
      Overrides:
      addComponent in class Container
    • addComponent

      public void addComponent(Object constraints, Component cmp)
      Description copied from class: Container

      Adds a Component to the Container

      Parameters
      • constraints: @param constraints this method is useful when the Layout requires a constraint such as the BorderLayout. In this case you need to specify an additional data when you add a Component, such as "CENTER", "NORTH"...

      • cmp: component to add

      Overrides:
      addComponent in class Container
    • removeComponent

      public void removeComponent(Component cmp)
      Description copied from class: Container

      removes a Component from the Container, notice that removed component might still have a pending repaint in the queue that won't be removed. Calling form.repaint() will workaround such an issue.

      Parameters
      • cmp: the removed component
      Overrides:
      removeComponent in class Container
    • removeAll

      public void removeAll()
      Description copied from class: Container
      remove all Components from container, notice that removed component might still have a pending repaint in the queue that won't be removed. Calling form.repaint() will workaround such an issue. Notice that this method doesn't recurse and only removes from the current container.
      Overrides:
      removeAll in class Container