Class ScrolledWindow

All Implemented Interfaces:
PointerInterface

public class ScrolledWindow extends Widget
`GtkScrolledWindow` is a container that makes its child scrollable.

It does so using either internally added scrollbars or externally
associated adjustments, and optionally draws a frame around the child.

Widgets with native scrolling support, i.e. those whose classes implement
the [iface@Gtk.Scrollable] interface, are added directly. For other types
of widget, the class [class@Gtk.Viewport] acts as an adaptor, giving
scrollability to other widgets. [method@Gtk.ScrolledWindow.set_child]
intelligently accounts for whether or not the added child is a `GtkScrollable`.
If it isn’t, then it wraps the child in a `GtkViewport`. Therefore, you can
just add any child widget and not worry about the details.

If [method@Gtk.ScrolledWindow.set_child] has added a `GtkViewport` for you,
you can remove both your added child widget from the `GtkViewport`, and the
`GtkViewport` from the `GtkScrolledWindow`, like this:

```c
GtkWidget *scrolled_window = gtk_scrolled_window_new ();
GtkWidget *child_widget = gtk_button_new ();

// GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically
// add a GtkViewport.
gtk_box_append (GTK_BOX (scrolled_window), child_widget);

// Either of these will result in child_widget being unparented:
gtk_box_remove (GTK_BOX (scrolled_window), child_widget);
// or
gtk_box_remove (GTK_BOX (scrolled_window),
gtk_bin_get_child (GTK_BIN (scrolled_window)));
```

Unless [property@Gtk.ScrolledWindow:hscrollbar-policy] and
[property@Gtk.ScrolledWindow:vscrollbar-policy] are %GTK_POLICY_NEVER or
%GTK_POLICY_EXTERNAL, `GtkScrolledWindow` adds internal `GtkScrollbar` widgets
around its child. The scroll position of the child, and if applicable the
scrollbars, is controlled by the [property@Gtk.ScrolledWindow:hadjustment]
and [property@Gtk.ScrolledWindow:vadjustment] that are associated with the
`GtkScrolledWindow`. See the docs on [class@Gtk.Scrollbar] for the details,
but note that the “step_increment” and “page_increment” fields are only
effective if the policy causes scrollbars to be present.

If a `GtkScrolledWindow` doesn’t behave quite as you would like, or
doesn’t have exactly the right layout, it’s very possible to set up
your own scrolling with `GtkScrollbar` and for example a `GtkGrid`.

# Touch support

`GtkScrolledWindow` has built-in support for touch devices. When a
touchscreen is used, swiping will move the scrolled window, and will
expose 'kinetic' behavior. This can be turned off with the
[property@Gtk.ScrolledWindow:kinetic-scrolling] property if it is undesired.

`GtkScrolledWindow` also displays visual 'overshoot' indication when
the content is pulled beyond the end, and this situation can be
captured with the [signal@Gtk.ScrolledWindow::edge-overshot] signal.

If no mouse device is present, the scrollbars will overlaid as
narrow, auto-hiding indicators over the content. If traditional
scrollbars are desired although no mouse is present, this behaviour
can be turned off with the [property@Gtk.ScrolledWindow:overlay-scrolling]
property.

# CSS nodes

`GtkScrolledWindow` has a main CSS node with name scrolledwindow.
It gets a .frame style class added when [property@Gtk.ScrolledWindow:has-frame]
is %TRUE.

It uses subnodes with names overshoot and undershoot to draw the overflow
and underflow indications. These nodes get the .left, .right, .top or .bottom
style class added depending on where the indication is drawn.

`GtkScrolledWindow` also sets the positional style classes (.left, .right,
.top, .bottom) and style classes related to overlay scrolling
(.overlay-indicator, .dragging, .hovering) on its scrollbars.

If both scrollbars are visible, the area where they meet is drawn
with a subnode named junction.

# Accessibility

`GtkScrolledWindow` uses the %GTK_ACCESSIBLE_ROLE_GROUP role.

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

  • Field Details

  • Constructor Details

    • ScrolledWindow

      public ScrolledWindow(PointerContainer pointer)
    • ScrolledWindow

      public ScrolledWindow()
      Creates a new scrolled window.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getChild

      public Widget getChild()
      Gets the child widget of @scrolled_window.
      Returns:
      the child widget of @scrolled_window
    • getHadjustment

      public Adjustment getHadjustment()
      Returns the horizontal scrollbar’s adjustment.

      This is the adjustment used to connect the horizontal scrollbar
      to the child widget’s horizontal scroll functionality.
      Returns:
      the horizontal `GtkAdjustment`
    • getHasFrame

      public boolean getHasFrame()
      Gets whether the scrolled window draws a frame.
      Returns:
      %TRUE if the @scrolled_window has a frame
    • getHscrollbar

      public Widget getHscrollbar()
      Returns the horizontal scrollbar of @scrolled_window.
      Returns:
      the horizontal scrollbar of the scrolled window.
    • getKineticScrolling

      public boolean getKineticScrolling()
      Returns the specified kinetic scrolling behavior.
      Returns:
      the scrolling behavior flags.
    • getMaxContentHeight

      public int getMaxContentHeight()
      Returns the maximum content height set.
      Returns:
      the maximum content height, or -1
    • getMaxContentWidth

      public int getMaxContentWidth()
      Returns the maximum content width set.
      Returns:
      the maximum content width, or -1
    • getMinContentHeight

      public int getMinContentHeight()
      Gets the minimal content height of @scrolled_window.
      Returns:
      the minimal content height
    • getMinContentWidth

      public int getMinContentWidth()
      Gets the minimum content width of @scrolled_window.
      Returns:
      the minimum content width
    • getOverlayScrolling

      public boolean getOverlayScrolling()
      Returns whether overlay scrolling is enabled for this scrolled window.
      Returns:
      %TRUE if overlay scrolling is enabled
    • getPlacement

      public int getPlacement()
      Gets the placement of the contents with respect to the scrollbars.
      Returns:
      the current placement value.
    • getPolicy

      public void getPolicy(@Nullable Int hscrollbar_policy, @Nullable Int vscrollbar_policy)
      Retrieves the current policy values for the horizontal and vertical
      scrollbars.

      See [method@Gtk.ScrolledWindow.set_policy].
      Parameters:
      hscrollbar_policy - location to store the policy for the horizontal scrollbar
      vscrollbar_policy - location to store the policy for the vertical scrollbar
    • getPropagateNaturalHeight

      public boolean getPropagateNaturalHeight()
      Reports whether the natural height of the child will be calculated
      and propagated through the scrolled window’s requested natural height.
      Returns:
      whether natural height propagation is enabled.
    • getPropagateNaturalWidth

      public boolean getPropagateNaturalWidth()
      Reports whether the natural width of the child will be calculated
      and propagated through the scrolled window’s requested natural width.
      Returns:
      whether natural width propagation is enabled.
    • getVadjustment

      public Adjustment getVadjustment()
      Returns the vertical scrollbar’s adjustment.

      This is the adjustment used to connect the vertical
      scrollbar to the child widget’s vertical scroll functionality.
      Returns:
      the vertical `GtkAdjustment`
    • getVscrollbar

      public Widget getVscrollbar()
      Returns the vertical scrollbar of @scrolled_window.
      Returns:
      the vertical scrollbar of the scrolled window.
    • setChild

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

      public void setHadjustment(@Nullable Adjustment hadjustment)
      Sets the `GtkAdjustment` for the horizontal scrollbar.
      Parameters:
      hadjustment - the `GtkAdjustment` to use, or %NULL to create a new one
    • setHasFrame

      public void setHasFrame(boolean has_frame)
      Changes the frame drawn around the contents of @scrolled_window.
      Parameters:
      has_frame - whether to draw a frame around scrolled window contents
    • setKineticScrolling

      public void setKineticScrolling(boolean kinetic_scrolling)
      Turns kinetic scrolling on or off.

      Kinetic scrolling only applies to devices with source
      %GDK_SOURCE_TOUCHSCREEN.
      Parameters:
      kinetic_scrolling - %TRUE to enable kinetic scrolling
    • setMaxContentHeight

      public void setMaxContentHeight(int height)
      Sets the maximum height that @scrolled_window should keep visible.

      The @scrolled_window will grow up to this height before it starts
      scrolling the content.

      It is a programming error to set the maximum content height to a value
      smaller than [property@Gtk.ScrolledWindow:min-content-height].
      Parameters:
      height - the maximum content height
    • setMaxContentWidth

      public void setMaxContentWidth(int width)
      Sets the maximum width that @scrolled_window should keep visible.

      The @scrolled_window will grow up to this width before it starts
      scrolling the content.

      It is a programming error to set the maximum content width to a
      value smaller than [property@Gtk.ScrolledWindow:min-content-width].
      Parameters:
      width - the maximum content width
    • setMinContentHeight

      public void setMinContentHeight(int height)
      Sets the minimum height that @scrolled_window should keep visible.

      Note that this can and (usually will) be smaller than the minimum
      size of the content.

      It is a programming error to set the minimum content height to a
      value greater than [property@Gtk.ScrolledWindow:max-content-height].
      Parameters:
      height - the minimal content height
    • setMinContentWidth

      public void setMinContentWidth(int width)
      Sets the minimum width that @scrolled_window should keep visible.

      Note that this can and (usually will) be smaller than the minimum
      size of the content.

      It is a programming error to set the minimum content width to a
      value greater than [property@Gtk.ScrolledWindow:max-content-width].
      Parameters:
      width - the minimal content width
    • setOverlayScrolling

      public void setOverlayScrolling(boolean overlay_scrolling)
      Enables or disables overlay scrolling for this scrolled window.
      Parameters:
      overlay_scrolling - whether to enable overlay scrolling
    • setPlacement

      public void setPlacement(int window_placement)
      Sets the placement of the contents with respect to the scrollbars
      for the scrolled window.

      The default is %GTK_CORNER_TOP_LEFT, meaning the child is
      in the top left, with the scrollbars underneath and to the right.
      Other values in [enum@Gtk.CornerType] are %GTK_CORNER_TOP_RIGHT,
      %GTK_CORNER_BOTTOM_LEFT, and %GTK_CORNER_BOTTOM_RIGHT.

      See also [method@Gtk.ScrolledWindow.get_placement] and
      [method@Gtk.ScrolledWindow.unset_placement].
      Parameters:
      window_placement - position of the child window
    • setPolicy

      public void setPolicy(int hscrollbar_policy, int vscrollbar_policy)
      Sets the scrollbar policy for the horizontal and vertical scrollbars.

      The policy determines when the scrollbar should appear; it is a value
      from the [enum@Gtk.PolicyType] enumeration. If %GTK_POLICY_ALWAYS, the
      scrollbar is always present; if %GTK_POLICY_NEVER, the scrollbar is
      never present; if %GTK_POLICY_AUTOMATIC, the scrollbar is present only
      if needed (that is, if the slider part of the bar would be smaller
      than the trough — the display is larger than the page size).
      Parameters:
      hscrollbar_policy - policy for horizontal bar
      vscrollbar_policy - policy for vertical bar
    • setPropagateNaturalHeight

      public void setPropagateNaturalHeight(boolean propagate)
      Sets whether the natural height of the child should be calculated
      and propagated through the scrolled window’s requested natural height.
      Parameters:
      propagate - whether to propagate natural height
    • setPropagateNaturalWidth

      public void setPropagateNaturalWidth(boolean propagate)
      Sets whether the natural width of the child should be calculated
      and propagated through the scrolled window’s requested natural width.
      Parameters:
      propagate - whether to propagate natural width
    • setVadjustment

      public void setVadjustment(@Nullable Adjustment vadjustment)
      Sets the `GtkAdjustment` for the vertical scrollbar.
      Parameters:
      vadjustment - the `GtkAdjustment` to use, or %NULL to create a new one
    • unsetPlacement

      public void unsetPlacement()
      Unsets the placement of the contents with respect to the scrollbars.

      If no window placement is set for a scrolled window,
      it defaults to %GTK_CORNER_TOP_LEFT.
    • onEdgeOvershot

      public SignalHandler onEdgeOvershot(ScrolledWindow.OnEdgeOvershot signal)
      Connect to signal "edge-overshot".
      See ScrolledWindow.OnEdgeOvershot.onEdgeOvershot(int) for signal description.
      Field SIGNAL_ON_EDGE_OVERSHOT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onEdgeReached

      public SignalHandler onEdgeReached(ScrolledWindow.OnEdgeReached signal)
      Connect to signal "edge-reached".
      See ScrolledWindow.OnEdgeReached.onEdgeReached(int) for signal description.
      Field SIGNAL_ON_EDGE_REACHED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onMoveFocusOut

      public SignalHandler onMoveFocusOut(ScrolledWindow.OnMoveFocusOut signal)
      Connect to signal "move-focus-out".
      See ScrolledWindow.OnMoveFocusOut.onMoveFocusOut(int) for signal description.
      Field SIGNAL_ON_MOVE_FOCUS_OUT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onScrollChild

      public SignalHandler onScrollChild(ScrolledWindow.OnScrollChild signal)
      Connect to signal "scroll-child".
      See ScrolledWindow.OnScrollChild.onScrollChild(int, boolean) for signal description.
      Field SIGNAL_ON_SCROLL_CHILD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • 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
    • 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()