Gtk.ScrolledWindow

const Gtk = imports.gi.Gtk;

let scrolled_window = new Gtk.ScrolledWindow({
    hadjustment: value,
    hscrollbar_policy: value,
    kinetic_scrolling: value,
    min_content_height: value,
    min_content_width: value,
    shadow_type: value,
    vadjustment: value,
    vscrollbar_policy: value,
    window_placement: value,
    window_placement_set: value,
});
  

Gtk.ScrolledWindow is a Gtk.Bin subclass: it's a container the accepts a single child widget. Gtk.ScrolledWindow adds scrollbars to the child widget and optionally draws a beveled frame around the child widget.

The scrolled window can work in two ways. Some widgets have native scrolling support; these widgets implement the Gtk.Scrollable interface. Widgets with native scroll support include Gtk.TreeView, Gtk.TextView, and Gtk.Layout.

For widgets that lack native scrolling support, the Gtk.Viewport widget acts as an adaptor class, implementing scrollability for child widgets that lack their own scrolling capabilities. Use Gtk.Viewport to scroll child widgets such as Gtk.Grid, Gtk.Box, and so on.

If a widget has native scrolling abilities, it can be added to the Gtk.ScrolledWindow with Gtk.Container.prototype.add. If a widget does not, you must first add the widget to a Gtk.Viewport, then add the Gtk.Viewport to the scrolled window. Gtk.Container.prototype.add will do this for you for widgets that don't implement Gtk.Scrollable natively, so you can ignore the presence of the viewport.

The position of the scrollbars is controlled by the scroll adjustments. See Gtk.Adjustment for the fields in an adjustment - for Gtk.Scrollbar, used by Gtk.ScrolledWindow, the "value" field represents the position of the scrollbar, which must be between the "lower" field and "upper - page_size." The "page_size" field represents the size of the visible scrollable area. The "step_increment" and "page_increment" fields are used when the user asks to step down (using the small stepper arrows) or page down (using for example the PageDown key).

If a Gtk.ScrolledWindow 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 Gtk.Scrollbar and for example a Gtk.Grid.

Hierarchy

  • GObject.Object
    • GObject.InitiallyUnowned
      • Gtk.Widget
        • Gtk.Container
          • Gtk.Bin
            • Gtk.ScrolledWindow