Class Viewport

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

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

Implements scrollability for widgets that don't support scrolling on their own.

Use GtkViewport to scroll child widgets such as GtkGrid, GtkBox, and so on.

The GtkViewport will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.

CSS nodes

GtkViewport has a single CSS node with name viewport.

Accessibility

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

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

  • Constructor Details

    • Viewport

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

      public Viewport(@Nullable Adjustment hadjustment, @Nullable Adjustment vadjustment)

      Creates a new GtkViewport.

      The new viewport uses the given adjustments, or default adjustments if none are given.

      Parameters:
      hadjustment - horizontal adjustment
      vadjustment - vertical adjustment
    • Viewport

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

    • getType

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

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

      protected Viewport 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
    • getChild

      public @Nullable Widget getChild()
      Gets the child widget of viewport.
      Returns:
      the child widget of this Viewport
    • getScrollToFocus

      public boolean getScrollToFocus()
      Gets whether the viewport is scrolling to keep the focused child in view.
      Returns:
      true if the viewport keeps the focus child scrolled to view
    • scrollTo

      public void scrollTo(Widget descendant, @Nullable ScrollInfo scroll)

      Scrolls a descendant of the viewport into view.

      The viewport and the descendant must be visible and mapped for this function to work, otherwise no scrolling will be performed.

      Parameters:
      descendant - a descendant widget of the viewport
      scroll - details of how to perform the scroll operation or NULL to scroll into view
      Since:
      4.12
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the child widget of viewport.
      Parameters:
      child - the child widget
    • setScrollToFocus

      public void setScrollToFocus(boolean scrollToFocus)
      Sets whether the viewport should automatically scroll to keep the focused child in view.
      Parameters:
      scrollToFocus - whether to keep the focus widget scrolled to view
    • builder

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