Class Stack

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

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

Shows one of its children at a time.

An example GtkStack

In contrast to GtkNotebook, GtkStack does not provide a means for users to change the visible child. Instead, a separate widget such as StackSwitcher or StackSidebar can be used with GtkStack to provide this functionality.

Transitions between pages can be animated as slides or fades. This can be controlled with setTransitionType(StackTransitionType). These animations respect the Gtk.Settings:gtk-enable-animations setting.

GtkStack maintains a StackPage object for each added child, which holds additional per-child properties. You obtain the GtkStackPage for a child with getPage(Widget) and you can obtain a GtkSelectionModel containing all the pages with getPages().

GtkStack as GtkBuildable

To set child-specific properties in a .ui file, create GtkStackPage objects explicitly, and set the child widget as a property on it:

  <object class="GtkStack" id="stack">
    <child>
      <object class="GtkStackPage">
        <property name="name">page1</property>
        <property name="title">In the beginning…</property>
        <property name="child">
          <object class="GtkLabel">
            <property name="label">It was dark</property>
          </object>
        </property>
      </object>
    </child>

CSS nodes

GtkStack has a single CSS node named stack.

Accessibility

GtkStack uses the Gtk.AccessibleRole.tab_panel role for the stack pages, which are the accessible parent objects of the child widgets.

  • Constructor Details

    • Stack

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

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

    • getType

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

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

      protected Stack 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
    • addChild

      public StackPage addChild(Widget child)
      Adds a child to stack.
      Parameters:
      child - the widget to add
      Returns:
      the GtkStackPage for child
    • addNamed

      public StackPage addNamed(Widget child, @Nullable String name)

      Adds a child to stack.

      The child is identified by the name.

      Parameters:
      child - the widget to add
      name - the name for child
      Returns:
      the GtkStackPage for child
    • addTitled

      public StackPage addTitled(Widget child, @Nullable String name, String title)

      Adds a child to stack.

      The child is identified by the name. The title will be used by GtkStackSwitcher to represent child in a tab bar, so it should be short.

      Parameters:
      child - the widget to add
      name - the name for child
      title - a human-readable title for child
      Returns:
      the GtkStackPage for child
    • getChildByName

      public @Nullable Widget getChildByName(String name)

      Finds the child with the name given as the argument.

      Returns null if there is no child with this name.

      Parameters:
      name - the name of the child to find
      Returns:
      the requested child of the GtkStack
    • getHhomogeneous

      public boolean getHhomogeneous()
      Gets whether this Stack is horizontally homogeneous.
      Returns:
      whether this Stack is horizontally homogeneous.
    • getInterpolateSize

      public boolean getInterpolateSize()
      Returns whether the GtkStack is set up to interpolate between the sizes of children on page switch.
      Returns:
      true if child sizes are interpolated
    • getPage

      public StackPage getPage(Widget child)
      Returns the GtkStackPage object for child.
      Parameters:
      child - a child of this Stack
      Returns:
      the GtkStackPage for child
    • getPages

      public SelectionModel getPages()

      Returns a GListModel that contains the pages of the stack.

      This can be used to keep an up-to-date view. The model also implements SelectionModel and can be used to track and modify the visible page.

      Returns:
      a GtkSelectionModel for the stack's children
    • getTransitionDuration

      public int getTransitionDuration()
      Returns the amount of time (in milliseconds) that transitions between pages in this Stack will take.
      Returns:
      the transition duration
    • getTransitionRunning

      public boolean getTransitionRunning()
      Returns whether the this Stack is currently in a transition from one page to another.
      Returns:
      true if the transition is currently running, false otherwise.
    • getTransitionType

      public StackTransitionType getTransitionType()
      Gets the type of animation that will be used for transitions between pages in stack.
      Returns:
      the current transition type of this Stack
    • getVhomogeneous

      public boolean getVhomogeneous()
      Gets whether this Stack is vertically homogeneous.
      Returns:
      whether this Stack is vertically homogeneous.
    • getVisibleChild

      public @Nullable Widget getVisibleChild()

      Gets the currently visible child of stack.

      Returns null if there are no visible children.

      Returns:
      the visible child of the GtkStack
    • getVisibleChildName

      public @Nullable String getVisibleChildName()

      Returns the name of the currently visible child of stack.

      Returns null if there is no visible child.

      Returns:
      the name of the visible child of the GtkStack
    • remove

      public void remove(Widget child)
      Removes a child widget from stack.
      Parameters:
      child - the child to remove
    • setHhomogeneous

      public void setHhomogeneous(boolean hhomogeneous)

      Sets the GtkStack to be horizontally homogeneous or not.

      If it is homogeneous, the GtkStack will request the same width for all its children. If it isn't, the stack may change width when a different child becomes visible.

      Parameters:
      hhomogeneous - true to make this Stack horizontally homogeneous
    • setInterpolateSize

      public void setInterpolateSize(boolean interpolateSize)

      Sets whether or not this Stack will interpolate its size when changing the visible child.

      If the Gtk.Stack:interpolate-size property is set to true, this Stack will interpolate its size between the current one and the one it'll take after changing the visible child, according to the set transition duration.

      Parameters:
      interpolateSize - the new value
    • setTransitionDuration

      public void setTransitionDuration(int duration)
      Sets the duration that transitions between pages in this Stack will take.
      Parameters:
      duration - the new duration, in milliseconds
    • setTransitionType

      public void setTransitionType(StackTransitionType transition)

      Sets the type of animation that will be used for transitions between pages in stack.

      Available types include various kinds of fades and slides.

      The transition type can be changed without problems at runtime, so it is possible to change the animation based on the page that is about to become current.

      Parameters:
      transition - the new transition type
    • setVhomogeneous

      public void setVhomogeneous(boolean vhomogeneous)

      Sets the GtkStack to be vertically homogeneous or not.

      If it is homogeneous, the GtkStack will request the same height for all its children. If it isn't, the stack may change height when a different child becomes visible.

      Parameters:
      vhomogeneous - true to make this Stack vertically homogeneous
    • setVisibleChild

      public void setVisibleChild(Widget child)

      Makes child the visible child of stack.

      If child is different from the currently visible child, the transition between the two will be animated with the current transition type of stack.

      Note that the child widget has to be visible itself (see Widget.show()) in order to become the visible child of stack.

      Parameters:
      child - a child of this Stack
    • setVisibleChildFull

      public void setVisibleChildFull(String name, StackTransitionType transition)

      Makes the child with the given name visible.

      Note that the child widget has to be visible itself (see Widget.show()) in order to become the visible child of stack.

      Parameters:
      name - the name of the child to make visible
      transition - the transition type to use
    • setVisibleChildName

      public void setVisibleChildName(String name)

      Makes the child with the given name visible.

      If child is different from the currently visible child, the transition between the two will be animated with the current transition type of stack.

      Note that the child widget has to be visible itself (see Widget.show()) in order to become the visible child of stack.

      Parameters:
      name - the name of the child to make visible
    • builder

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