Class CenterBox

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Proxy

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

Arranges three children in a row, keeping the middle child centered as well as possible.

An example GtkCenterBox

To add children to GtkCenterBox, use setStartWidget(Widget), setCenterWidget(Widget) and setEndWidget(Widget).

The sizing and positioning of children can be influenced with the align and expand properties of the children.

GtkCenterBox as GtkBuildable

The GtkCenterBox implementation of the GtkBuildable interface supports placing children in the 3 positions by specifying “start”, “center” or “end” as the “type” attribute of a <child> element.

CSS nodes

GtkCenterBox uses a single CSS node with the name “box”,

The first child of the GtkCenterBox will be allocated depending on the text direction, i.e. in left-to-right layouts it will be allocated on the left and in right-to-left layouts on the right.

In vertical orientation, the nodes of the children are arranged from top to bottom.

Accessibility

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

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

  • Constructor Details

    • CenterBox

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

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

    • getType

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

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

      protected CenterBox 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
    • getBaselinePosition

      public BaselinePosition getBaselinePosition()

      Gets the baseline position of the center box.

      See setBaselinePosition(BaselinePosition).

      Returns:
      the baseline position
    • getCenterWidget

      public @Nullable Widget getCenterWidget()
      Gets the center widget.
      Returns:
      the center widget
    • getEndWidget

      public @Nullable Widget getEndWidget()
      Gets the end widget.
      Returns:
      the end widget
    • getShrinkCenterLast

      public boolean getShrinkCenterLast()
      Gets whether the center widget shrinks after other children.
      Returns:
      whether to shrink the center widget after others
      Since:
      4.12
    • getStartWidget

      public @Nullable Widget getStartWidget()
      Gets the start widget.
      Returns:
      the start widget
    • setBaselinePosition

      public void setBaselinePosition(BaselinePosition position)

      Sets the baseline position of a center 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
    • setCenterWidget

      public void setCenterWidget(@Nullable Widget child)

      Sets the center widget.

      To remove the existing center widget, pass NULL.

      Parameters:
      child - the new center widget
    • setEndWidget

      public void setEndWidget(@Nullable Widget child)

      Sets the end widget.

      To remove the existing end widget, pass NULL.

      Parameters:
      child - the new end widget
    • setShrinkCenterLast

      public void setShrinkCenterLast(boolean shrinkCenterLast)

      Sets whether to shrink the center widget after other children.

      By default, when there's no space to give all three children their natural widths, the start and end widgets start shrinking and the center child keeps natural width until they reach minimum width.

      If shrinkCenterLast is false, start and end widgets keep natural width and the center widget starts shrinking instead.

      Parameters:
      shrinkCenterLast - whether to shrink the center widget after others
      Since:
      4.12
    • setStartWidget

      public void setStartWidget(@Nullable Widget child)

      Sets the start widget.

      To remove the existing start widget, pass NULL.

      Parameters:
      child - the new start widget
    • builder

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