Class ScrolledWindow
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Proxy
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(org.gnome.gtk.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(org.gnome.gtk.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classScrolledWindow.Builder<B extends ScrolledWindow.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theEdgeOvershotCallbackcallback.static interfaceFunctional interface declaration of theEdgeReachedCallbackcallback.static interfaceFunctional interface declaration of theMoveFocusOutCallbackcallback.static interfaceFunctional interface declaration of theScrollChildCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ScrolledWindow.ScrolledWindow(MemorySegment address) Create a ScrolledWindow proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ScrolledWindowasParent()Returns this instance as if it were its parent type.static ScrolledWindow.Builder<? extends ScrolledWindow.Builder> builder()AScrolledWindow.Builderobject constructs aScrolledWindowwith the specified properties.voidEmits the "edge-overshot" signal.voidEmits the "edge-reached" signal.voidemitMoveFocusOut(DirectionType directionType) Emits the "move-focus-out" signal.booleanemitScrollChild(ScrollType scroll, boolean horizontal) Emits the "scroll-child" signal.@Nullable WidgetgetChild()Gets the child widget ofscrolledWindow.Returns the horizontal scrollbar’s adjustment.booleanGets whether the scrolled window draws a frame.Returns the horizontal scrollbar ofscrolledWindow.booleanReturns the specified kinetic scrolling behavior.intReturns the maximum content height set.intReturns the maximum content width set.intGets the minimal content height ofscrolledWindow.intGets the minimum content width ofscrolledWindow.booleanReturns whether overlay scrolling is enabled for this scrolled window.Gets the placement of the contents with respect to the scrollbars.voidgetPolicy(@Nullable Out<PolicyType> hscrollbarPolicy, @Nullable Out<PolicyType> vscrollbarPolicy) Retrieves the current policy values for the horizontal and vertical scrollbars.booleanReports whether the natural height of the child will be calculated and propagated through the scrolled window’s requested natural height.booleanReports whether the natural width of the child will be calculated and propagated through the scrolled window’s requested natural width.static @Nullable TypegetType()Get the GType of the ScrolledWindow classReturns the vertical scrollbar’s adjustment.Returns the vertical scrollbar ofscrolledWindow.Emitted whenever user initiated scrolling makes the scrolled window firmly surpass the limits defined by the adjustment in that orientation.Emitted whenever user-initiated scrolling makes the scrolled window exactly reach the lower or upper limits defined by the adjustment in that orientation.Emitted when focus is moved away from the scrolled window by a keybinding.Emitted when a keybinding that scrolls is pressed.voidSets the child widget ofscrolledWindow.voidsetHadjustment(@Nullable Adjustment hadjustment) Sets theGtkAdjustmentfor the horizontal scrollbar.voidsetHasFrame(boolean hasFrame) Changes the frame drawn around the contents ofscrolledWindow.voidsetKineticScrolling(boolean kineticScrolling) Turns kinetic scrolling on or off.voidsetMaxContentHeight(int height) Sets the maximum height that this ScrolledWindow should keep visible.voidsetMaxContentWidth(int width) Sets the maximum width that this ScrolledWindow should keep visible.voidsetMinContentHeight(int height) Sets the minimum height that this ScrolledWindow should keep visible.voidsetMinContentWidth(int width) Sets the minimum width that this ScrolledWindow should keep visible.voidsetOverlayScrolling(boolean overlayScrolling) Enables or disables overlay scrolling for this scrolled window.voidsetPlacement(CornerType windowPlacement) Sets the placement of the contents with respect to the scrollbars for the scrolled window.voidsetPolicy(PolicyType hscrollbarPolicy, PolicyType vscrollbarPolicy) Sets the scrollbar policy for the horizontal and vertical scrollbars.voidsetPropagateNaturalHeight(boolean propagate) Sets whether the natural height of the child should be calculated and propagated through the scrolled window’s requested natural height.voidsetPropagateNaturalWidth(boolean propagate) Sets whether the natural width of the child should be calculated and propagated through the scrolled window’s requested natural width.voidsetVadjustment(@Nullable Adjustment vadjustment) Sets theGtkAdjustmentfor the vertical scrollbar.voidUnsets the placement of the contents with respect to the scrollbars.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
ScrolledWindow
Create a ScrolledWindow proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
ScrolledWindow
public ScrolledWindow()Creates a new ScrolledWindow.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getChild
Gets the child widget ofscrolledWindow.If the scrolled window automatically added a
Viewport, this function will return the viewport widget, and you can retrieve its child usingViewport.getChild().- Returns:
- the child widget of this ScrolledWindow
-
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:
trueif the this ScrolledWindow has a frame
-
getHscrollbar
Returns the horizontal scrollbar ofscrolledWindow.- 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 ofscrolledWindow.- Returns:
- the minimal content height
-
getMinContentWidth
public int getMinContentWidth()Gets the minimum content width ofscrolledWindow.- Returns:
- the minimum content width
-
getOverlayScrolling
public boolean getOverlayScrolling()Returns whether overlay scrolling is enabled for this scrolled window.- Returns:
trueif overlay scrolling is enabled
-
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(org.gnome.gtk.PolicyType, org.gnome.gtk.PolicyType).- Parameters:
hscrollbarPolicy- location to store the policy for the horizontal scrollbarvscrollbarPolicy- 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
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
Returns the vertical scrollbar ofscrolledWindow.- Returns:
- the vertical scrollbar of the scrolled window.
-
setChild
Sets the child widget ofscrolledWindow.If
childdoes not implement theScrollableinterface, the scrolled window will addchildto aViewportinstance and then add the viewport as its child widget.- Parameters:
child- the child widget
-
setHadjustment
Sets theGtkAdjustmentfor the horizontal scrollbar.- Parameters:
hadjustment- theGtkAdjustmentto use, ornullto create a new one
-
setHasFrame
public void setHasFrame(boolean hasFrame) Changes the frame drawn around the contents ofscrolledWindow.- 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-trueto 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
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 inGtk.CornerTypeareCornerType.TOP_RIGHT,CornerType.BOTTOM_LEFT, andCornerType.BOTTOM_RIGHT.See also
getPlacement()andunsetPlacement().- Parameters:
windowPlacement- position of the child window
-
setPolicy
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.PolicyTypeenumeration. IfPolicyType.ALWAYS, the scrollbar is always present; ifPolicyType.NEVER, the scrollbar is never present; ifPolicyType.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 barvscrollbarPolicy- 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
Sets theGtkAdjustmentfor the vertical scrollbar.- Parameters:
vadjustment- theGtkAdjustmentto use, ornullto 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
public SignalConnection<ScrolledWindow.EdgeOvershotCallback> onEdgeOvershot(ScrolledWindow.EdgeOvershotCallback handler) 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-reachedsignal.Note: The
posargument 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
Emits the "edge-overshot" signal. SeeonEdgeOvershot(org.gnome.gtk.ScrolledWindow.EdgeOvershotCallback). -
onEdgeReached
public SignalConnection<ScrolledWindow.EdgeReachedCallback> onEdgeReached(ScrolledWindow.EdgeReachedCallback handler) 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-overshotsignal.Note: The
posargument 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
Emits the "edge-reached" signal. SeeonEdgeReached(org.gnome.gtk.ScrolledWindow.EdgeReachedCallback). -
onMoveFocusOut
public SignalConnection<ScrolledWindow.MoveFocusOutCallback> onMoveFocusOut(ScrolledWindow.MoveFocusOutCallback handler) 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+Tabto move forward andCtrl+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
Emits the "move-focus-out" signal. SeeonMoveFocusOut(org.gnome.gtk.ScrolledWindow.MoveFocusOutCallback). -
onScrollChild
public SignalConnection<ScrolledWindow.ScrollChildCallback> onScrollChild(ScrolledWindow.ScrollChildCallback handler) 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
Emits the "scroll-child" signal. SeeonScrollChild(org.gnome.gtk.ScrolledWindow.ScrollChildCallback). -
builder
AScrolledWindow.Builderobject constructs aScrolledWindowwith the specified properties. Use the variousset...()methods to set properties, and finish construction withScrolledWindow.Builder.build().- Returns:
- the builder object
-