Class Box

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Proxy
Direct Known Subclasses:
ShortcutsGroup, ShortcutsSection

@Generated("org.javagi.JavaGI") public class Box extends Widget implements Accessible, Buildable, ConstraintTarget, Orientable

Arranges child widgets into a single row or column.

An example GtkBox

Whether it is a row or column depends on the value of its Gtk.Orientable:orientation property. Within the other dimension, all children are allocated the same size. The Gtk.Widget:halign and Gtk.Widget:valign properties can be used on the children to influence their allocation.

Use repeated calls to append(Widget) to pack widgets into a GtkBox from start to end. Use remove(Widget) to remove widgets from the GtkBox. insertChildAfter(Widget, Widget) can be used to add a child at a particular position.

Use setHomogeneous(boolean) to specify whether or not all children of the GtkBox are forced to get the same amount of space.

Use setSpacing(int) to determine how much space will be minimally placed between all children in the GtkBox. Note that spacing is added between the children.

Use reorderChildAfter(Widget, Widget) to move a child to a different place in the box.

CSS nodes

GtkBox uses a single CSS node with name box.

Accessibility

Until GTK 4.10, GtkBox used the Gtk.AccessibleRole.group role.

Starting from GTK 4.12, GtkBox uses the Gtk.AccessibleRole.generic role.

  • Constructor Details

    • Box

      public Box(MemorySegment address)
      Create a Box instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Box

      public Box(Orientation orientation, int spacing)
      Creates a new box.
      Parameters:
      orientation - the box’s orientation
      spacing - the number of pixels to place between children
    • Box

      public Box()
      Create a new Box.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Box class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Box asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • append

      public void append(Widget child)
      Adds a child at the end.
      Parameters:
      child - the widget to append
    • getBaselineChild

      public int getBaselineChild()
      Gets the value set by setBaselineChild(int).
      Returns:
      the baseline child
      Since:
      4.12
    • getBaselinePosition

      public BaselinePosition getBaselinePosition()
      Returns:
      the baseline position
    • getHomogeneous

      public boolean getHomogeneous()

      Returns whether the box is homogeneous.

      In a homogeneous box all children are the same size.

      Returns:
      true if the box is homogeneous
    • getSpacing

      public int getSpacing()
      Gets the value set by setSpacing(int).
      Returns:
      spacing between children
    • insertChildAfter

      public void insertChildAfter(Widget child, @Nullable Widget sibling)

      Inserts a child at a specific position.

      The child is added after sibling in the list of this Box children.

      If sibling is NULL, the child is placed at the beginning.

      Parameters:
      child - the widget to insert
      sibling - the sibling after which to insert child
    • prepend

      public void prepend(Widget child)
      Adds a child at the beginning.
      Parameters:
      child - the widget to prepend
    • remove

      public void remove(Widget child)

      Removes a child widget from the box.

      The child must have been added before with append(Widget), prepend(Widget), or insertChildAfter(Widget, Widget).

      Parameters:
      child - the child to remove
    • reorderChildAfter

      public void reorderChildAfter(Widget child, @Nullable Widget sibling)

      Moves a child to a different position.

      The child is moved to the position after sibling in the list of this Box children.

      If sibling is NULL, the child is placed at the beginning.

      Parameters:
      child - the widget to move, must be a child of this Box
      sibling - the sibling to move child after
    • setBaselineChild

      public void setBaselineChild(int child)

      Sets the baseline child of a box.

      This affects only vertical boxes.

      Parameters:
      child - a child position, or -1
      Since:
      4.12
    • setBaselinePosition

      public void setBaselinePosition(BaselinePosition position)

      Sets the baseline position of a box.

      This affects only horizontal boxes with at least one baseline aligned child. If there is more vertical space available than requested, and the baseline is not allocated by the parent then position is used to allocate the baseline with respect to the extra space available.

      Parameters:
      position - the baseline position
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets whether or not all children are given equal space in the box.
      Parameters:
      homogeneous - true to create equal allotments, false for variable allotments
    • setSpacing

      public void setSpacing(int spacing)
      Sets the number of pixels to place between children.
      Parameters:
      spacing - the number of pixels to put between children
    • builder

      public static Box.Builder<? extends Box.Builder> builder()
      A Box.Builder object constructs a Box with the specified properties. Use the various set...() methods to set properties, and finish construction with Box.Builder.build().
      Returns:
      the builder object