Class ScrolledWindow

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

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

Makes its child scrollable.

An example GtkScrolledWindow

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 Scrollable interface, are added directly. For other types of widget, the class Viewport acts as an adaptor, giving scrollability to other widgets. setChild(Widget) 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 setChild(Widget) has added a GtkViewport for you, it will be automatically removed when you unset the child. Unless Gtk.ScrolledWindow:hscrollbar-policy and Gtk.ScrolledWindow:vscrollbar-policy are PolicyType.NEVER or PolicyType.EXTERNAL, GtkScrolledWindow adds internal GtkScrollbar widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by the Gtk.ScrolledWindow:hadjustment and Gtk.ScrolledWindow:vadjustment that are associated with the GtkScrolledWindow. See the docs on 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 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 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 Gtk.ScrolledWindow:overlay-scrolling property.

Shortcuts and Gestures

The following signals have default keybindings:

  • Gtk.ScrolledWindow::scroll-child

CSS nodes

GtkScrolledWindow has a main CSS node with name scrolledwindow. It gets a .frame style class added when 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

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

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

  • Constructor Details

    • ScrolledWindow

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

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

    • getType

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

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

      protected ScrolledWindow 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 scrolledWindow.

      If the scrolled window automatically added a Viewport, this function will return the viewport widget, and you can retrieve its child using Viewport.getChild().

      Returns:
      the child widget of this ScrolledWindow
    • 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 this ScrolledWindow has a frame
    • getHscrollbar

      public Widget getHscrollbar()
      Returns the horizontal scrollbar of scrolledWindow.
      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 scrolledWindow.
      Returns:
      the minimal content height
    • getMinContentWidth

      public int getMinContentWidth()
      Gets the minimum content width of scrolledWindow.
      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 CornerType getPlacement()
      Gets the placement of the contents with respect to the scrollbars.
      Returns:
      the current placement value.
    • getPolicy

      public void getPolicy(@Nullable Out<PolicyType> hscrollbarPolicy, @Nullable Out<PolicyType> vscrollbarPolicy)

      Retrieves the current policy values for the horizontal and vertical scrollbars.

      See setPolicy(PolicyType, PolicyType).

      Parameters:
      hscrollbarPolicy - location to store the policy for the horizontal scrollbar
      vscrollbarPolicy - 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 scrolledWindow.
      Returns:
      the vertical scrollbar of the scrolled window.
    • setChild

      public void setChild(@Nullable Widget child)

      Sets the child widget of scrolledWindow.

      If child does not implement the Scrollable interface, the scrolled window will add child to a Viewport instance and then add the viewport as its child widget.

      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 hasFrame)
      Changes the frame drawn around the contents of scrolledWindow.
      Parameters:
      hasFrame - whether to draw a frame around scrolled window contents
    • setKineticScrolling

      public void setKineticScrolling(boolean kineticScrolling)

      Turns kinetic scrolling on or off.

      Kinetic scrolling only applies to devices with source InputSource.TOUCHSCREEN.

      Parameters:
      kineticScrolling - true to enable kinetic scrolling
    • setMaxContentHeight

      public void setMaxContentHeight(int height)

      Sets the maximum height that this ScrolledWindow should keep visible.

      The this ScrolledWindow 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 Gtk.ScrolledWindow:min-content-height.

      Parameters:
      height - the maximum content height
    • setMaxContentWidth

      public void setMaxContentWidth(int width)

      Sets the maximum width that this ScrolledWindow should keep visible.

      The this ScrolledWindow 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 Gtk.ScrolledWindow:min-content-width.

      Parameters:
      width - the maximum content width
    • setMinContentHeight

      public void setMinContentHeight(int height)

      Sets the minimum height that this ScrolledWindow 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 Gtk.ScrolledWindow:max-content-height.

      Parameters:
      height - the minimal content height
    • setMinContentWidth

      public void setMinContentWidth(int width)

      Sets the minimum width that this ScrolledWindow 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 Gtk.ScrolledWindow:max-content-width.

      Parameters:
      width - the minimal content width
    • setOverlayScrolling

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

      public void setPlacement(CornerType windowPlacement)

      Sets the placement of the contents with respect to the scrollbars for the scrolled window.

      The default is CornerType.TOP_LEFT, meaning the child is in the top left, with the scrollbars underneath and to the right. Other values in Gtk.CornerType are CornerType.TOP_RIGHT, CornerType.BOTTOM_LEFT, and CornerType.BOTTOM_RIGHT.

      See also getPlacement() and unsetPlacement().

      Parameters:
      windowPlacement - position of the child window
    • setPolicy

      public void setPolicy(PolicyType hscrollbarPolicy, PolicyType vscrollbarPolicy)

      Sets the scrollbar policy for the horizontal and vertical scrollbars.

      The policy determines when the scrollbar should appear; it is a value from the Gtk.PolicyType enumeration. If PolicyType.ALWAYS, the scrollbar is always present; if PolicyType.NEVER, the scrollbar is never present; if PolicyType.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:
      hscrollbarPolicy - policy for horizontal bar
      vscrollbarPolicy - 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 CornerType.TOP_LEFT.

    • onEdgeOvershot

      Emitted whenever user initiated scrolling makes the scrolled window firmly surpass the limits defined by the adjustment in that orientation.

      A similar behavior without edge resistance is provided by the Gtk.ScrolledWindow::edge-reached signal.

      Note: The pos argument is LTR/RTL aware, so callers should be aware too if intending to provide behavior on horizontal edges.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitEdgeOvershot

      public void emitEdgeOvershot(PositionType pos)
      Emits the "edge-overshot" signal. See onEdgeOvershot(ScrolledWindow.EdgeOvershotCallback).
    • onEdgeReached

      Emitted whenever user-initiated scrolling makes the scrolled window exactly reach the lower or upper limits defined by the adjustment in that orientation.

      A similar behavior with edge resistance is provided by the Gtk.ScrolledWindow::edge-overshot signal.

      Note: The pos argument is LTR/RTL aware, so callers should be aware too if intending to provide behavior on horizontal edges.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitEdgeReached

      public void emitEdgeReached(PositionType pos)
      Emits the "edge-reached" signal. See onEdgeReached(ScrolledWindow.EdgeReachedCallback).
    • onMoveFocusOut

      Emitted when focus is moved away from the scrolled window by a keybinding.

      This is a keybinding signal.

      The default bindings for this signal are Ctrl+Tab to move forward and Ctrl+Shift+Tab` to move backward.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMoveFocusOut

      public void emitMoveFocusOut(DirectionType directionType)
      Emits the "move-focus-out" signal. See onMoveFocusOut(ScrolledWindow.MoveFocusOutCallback).
    • onScrollChild

      Emitted when a keybinding that scrolls is pressed.

      This is a keybinding signal.

      The horizontal or vertical adjustment is updated which triggers a signal that the scrolled window’s child may listen to and scroll itself.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitScrollChild

      public boolean emitScrollChild(ScrollType scroll, boolean horizontal)
      Emits the "scroll-child" signal. See onScrollChild(ScrolledWindow.ScrollChildCallback).
    • builder

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