Class Box

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
ShortcutsGroup, ShortcutsSection

public class Box extends Widget
The `GtkBox` widget arranges child widgets into a single row or column.

![An example GtkBox](box.png)

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

Use repeated calls to [method@Gtk.Box.append] to pack widgets into a
`GtkBox` from start to end. Use [method@Gtk.Box.remove] to remove widgets
from the `GtkBox`. [method@Gtk.Box.insert_child_after] can be used to add
a child at a particular position.

Use [method@Gtk.Box.set_homogeneous] to specify whether or not all children
of the `GtkBox` are forced to get the same amount of space.

Use [method@Gtk.Box.set_spacing] to determine how much space will be minimally
placed between all children in the `GtkBox`. Note that spacing is added
*between* the children.

Use [method@Gtk.Box.reorder_child_after] to move a child to a different
place in the box.

# CSS nodes

`GtkBox` uses a single CSS node with name box.

# Accessibility

`GtkBox` uses the %GTK_ACCESSIBLE_ROLE_GROUP role.

https://docs.gtk.org/gtk4/class.Box.html

  • Constructor Details

    • Box

      public Box(PointerContainer pointer)
    • Box

      public Box(int orientation, int spacing)
      Creates a new `GtkBox`.
      Parameters:
      orientation - the box’s orientation
      spacing - the number of pixels to place by default between children
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • append

      public void append(@Nonnull Widget child)
      Adds @child as the last child to @box.
      Parameters:
      child - the `GtkWidget` to append
    • getBaselinePosition

      public int getBaselinePosition()
      Gets the value set by gtk_box_set_baseline_position().
      Returns:
      the baseline position
    • getHomogeneous

      public boolean getHomogeneous()
      Returns whether the box is homogeneous (all children are the
      same size).
      Returns:
      %TRUE if the box is homogeneous.
    • getSpacing

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

      public void insertChildAfter(@Nonnull Widget child, @Nullable Widget sibling)
      Inserts @child in the position after @sibling in the list
      of @box children.

      If @sibling is %NULL, insert @child at the first position.
      Parameters:
      child - the `GtkWidget` to insert
      sibling - the sibling after which to insert @child
    • prepend

      public void prepend(@Nonnull Widget child)
      Adds @child as the first child to @box.
      Parameters:
      child - the `GtkWidget` to prepend
    • remove

      public void remove(@Nonnull Widget child)
      Removes a child widget from @box.

      The child must have been added before with
      [method@Gtk.Box.append], [method@Gtk.Box.prepend], or
      [method@Gtk.Box.insert_child_after].
      Parameters:
      child - the child to remove
    • reorderChildAfter

      public void reorderChildAfter(@Nonnull Widget child, @Nullable Widget sibling)
      Moves @child to the position after @sibling in the list
      of @box children.

      If @sibling is %NULL, move @child to the first position.
      Parameters:
      child - the `GtkWidget` to move, must be a child of @box
      sibling - the sibling to move @child after
    • setBaselinePosition

      public void setBaselinePosition(int 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 - a `GtkBaselinePosition`
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets whether or not all children of @box are given equal space
      in the box.
      Parameters:
      homogeneous - a boolean value, %TRUE to create equal allotments, %FALSE for variable allotments
    • setSpacing

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

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Returns:
      Orientable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()