Class ScrollPane

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

@DefaultProperty("content") public class ScrollPane extends Control
A Control that provides a scrolled, clipped viewport of its contents. It allows the user to scroll the content around either directly (panning) or by using scroll bars. The ScrollPane allows specification of the scroll bar policy, which determines when scroll bars are displayed: always, never, or only when they are needed. The scroll bar policy can be specified independently for the horizontal and vertical scroll bars.

The ScrollPane allows the application to set the current, minimum, and maximum values for positioning the contents in the horizontal and vertical directions. These values are mapped proportionally onto the layoutBounds of the contained node.

ScrollPane layout calculations are based on the layoutBounds rather than the boundsInParent (visual bounds) of the scroll node. If an application wants the scrolling to be based on the visual bounds of the node (for scaled content etc.), it needs to wrap the scroll node in a Group.

ScrollPane sets focusTraversable to false.

This example creates a ScrollPane, which contains a Rectangle:

 Rectangle rect = new Rectangle(200, 200, Color.RED);
 ScrollPane s1 = new ScrollPane();
 s1.setPrefSize(120, 120);
 s1.setContent(rect);
Image of the ScrollPane control
Since:
JavaFX 2.0
  • Property Details

  • Constructor Details

    • ScrollPane

      public ScrollPane()
      Creates a new ScrollPane.
    • ScrollPane

      public ScrollPane(Node content)
      Creates a new ScrollPane.
      Parameters:
      content - the initial content for the ScrollPane
      Since:
      JavaFX 8.0
  • Method Details

    • setHbarPolicy

      public final void setHbarPolicy(ScrollPane.ScrollBarPolicy value)
      Sets the value of the hbarPolicy property.
      Property description:
      Specifies the policy for showing the horizontal scroll bar.
      Parameters:
      value - the value for the hbarPolicy property
      See Also:
    • getHbarPolicy

      public final ScrollPane.ScrollBarPolicy getHbarPolicy()
      Gets the value of the hbarPolicy property.
      Property description:
      Specifies the policy for showing the horizontal scroll bar.
      Returns:
      the value of the hbarPolicy property
      See Also:
    • hbarPolicyProperty

      public final ObjectProperty<ScrollPane.ScrollBarPolicy> hbarPolicyProperty()
      Specifies the policy for showing the horizontal scroll bar.
      Returns:
      the hbarPolicy property
      See Also:
    • setVbarPolicy

      public final void setVbarPolicy(ScrollPane.ScrollBarPolicy value)
      Sets the value of the vbarPolicy property.
      Property description:
      Specifies the policy for showing the vertical scroll bar.
      Parameters:
      value - the value for the vbarPolicy property
      See Also:
    • getVbarPolicy

      public final ScrollPane.ScrollBarPolicy getVbarPolicy()
      Gets the value of the vbarPolicy property.
      Property description:
      Specifies the policy for showing the vertical scroll bar.
      Returns:
      the value of the vbarPolicy property
      See Also:
    • vbarPolicyProperty

      public final ObjectProperty<ScrollPane.ScrollBarPolicy> vbarPolicyProperty()
      Specifies the policy for showing the vertical scroll bar.
      Returns:
      the vbarPolicy property
      See Also:
    • setContent

      public final void setContent(Node value)
      Sets the value of the content property.
      Property description:
      The node used as the content of this ScrollPane.
      Parameters:
      value - the value for the content property
      See Also:
    • getContent

      public final Node getContent()
      Gets the value of the content property.
      Property description:
      The node used as the content of this ScrollPane.
      Returns:
      the value of the content property
      See Also:
    • contentProperty

      public final ObjectProperty<Node> contentProperty()
      The node used as the content of this ScrollPane.
      Returns:
      the content property
      See Also:
    • setHvalue

      public final void setHvalue(double value)
      Sets the value of the hvalue property.
      Property description:
      The current horizontal scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of hmin to hmax. When hvalue equals hmin, the contained node is positioned so that its layoutBounds minX is visible. When hvalue equals hmax, the contained node is positioned so that its layoutBounds maxX is visible. When hvalue is between hmin and hmax, the contained node is positioned proportionally between layoutBounds minX and layoutBounds maxX.
      Parameters:
      value - the value for the hvalue property
      See Also:
    • getHvalue

      public final double getHvalue()
      Gets the value of the hvalue property.
      Property description:
      The current horizontal scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of hmin to hmax. When hvalue equals hmin, the contained node is positioned so that its layoutBounds minX is visible. When hvalue equals hmax, the contained node is positioned so that its layoutBounds maxX is visible. When hvalue is between hmin and hmax, the contained node is positioned proportionally between layoutBounds minX and layoutBounds maxX.
      Returns:
      the value of the hvalue property
      See Also:
    • hvalueProperty

      public final DoubleProperty hvalueProperty()
      The current horizontal scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of hmin to hmax. When hvalue equals hmin, the contained node is positioned so that its layoutBounds minX is visible. When hvalue equals hmax, the contained node is positioned so that its layoutBounds maxX is visible. When hvalue is between hmin and hmax, the contained node is positioned proportionally between layoutBounds minX and layoutBounds maxX.
      Returns:
      the hvalue property
      See Also:
    • setVvalue

      public final void setVvalue(double value)
      Sets the value of the vvalue property.
      Property description:
      The current vertical scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of vmin to vmax. When vvalue equals vmin, the contained node is positioned so that its layoutBounds minY is visible. When vvalue equals vmax, the contained node is positioned so that its layoutBounds maxY is visible. When vvalue is between vmin and vmax, the contained node is positioned proportionally between layoutBounds minY and layoutBounds maxY.
      Parameters:
      value - the value for the vvalue property
      See Also:
    • getVvalue

      public final double getVvalue()
      Gets the value of the vvalue property.
      Property description:
      The current vertical scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of vmin to vmax. When vvalue equals vmin, the contained node is positioned so that its layoutBounds minY is visible. When vvalue equals vmax, the contained node is positioned so that its layoutBounds maxY is visible. When vvalue is between vmin and vmax, the contained node is positioned proportionally between layoutBounds minY and layoutBounds maxY.
      Returns:
      the value of the vvalue property
      See Also:
    • vvalueProperty

      public final DoubleProperty vvalueProperty()
      The current vertical scroll position of the ScrollPane. This value may be set by the application to scroll the view programmatically. The ScrollPane will update this value whenever the viewport is scrolled or panned by the user. This value must always be within the range of vmin to vmax. When vvalue equals vmin, the contained node is positioned so that its layoutBounds minY is visible. When vvalue equals vmax, the contained node is positioned so that its layoutBounds maxY is visible. When vvalue is between vmin and vmax, the contained node is positioned proportionally between layoutBounds minY and layoutBounds maxY.
      Returns:
      the vvalue property
      See Also:
    • setHmin

      public final void setHmin(double value)
      Sets the value of the hmin property.
      Property description:
      The minimum allowable hvalue for this ScrollPane. Default value is 0.
      Parameters:
      value - the value for the hmin property
      See Also:
    • getHmin

      public final double getHmin()
      Gets the value of the hmin property.
      Property description:
      The minimum allowable hvalue for this ScrollPane. Default value is 0.
      Returns:
      the value of the hmin property
      See Also:
    • hminProperty

      public final DoubleProperty hminProperty()
      The minimum allowable hvalue for this ScrollPane. Default value is 0.
      Returns:
      the hmin property
      See Also:
    • setVmin

      public final void setVmin(double value)
      Sets the value of the vmin property.
      Property description:
      The minimum allowable vvalue for this ScrollPane. Default value is 0.
      Parameters:
      value - the value for the vmin property
      See Also:
    • getVmin

      public final double getVmin()
      Gets the value of the vmin property.
      Property description:
      The minimum allowable vvalue for this ScrollPane. Default value is 0.
      Returns:
      the value of the vmin property
      See Also:
    • vminProperty

      public final DoubleProperty vminProperty()
      The minimum allowable vvalue for this ScrollPane. Default value is 0.
      Returns:
      the vmin property
      See Also:
    • setHmax

      public final void setHmax(double value)
      Sets the value of the hmax property.
      Property description:
      The maximum allowable hvalue for this ScrollPane. Default value is 1.
      Parameters:
      value - the value for the hmax property
      See Also:
    • getHmax

      public final double getHmax()
      Gets the value of the hmax property.
      Property description:
      The maximum allowable hvalue for this ScrollPane. Default value is 1.
      Returns:
      the value of the hmax property
      See Also:
    • hmaxProperty

      public final DoubleProperty hmaxProperty()
      The maximum allowable hvalue for this ScrollPane. Default value is 1.
      Returns:
      the hmax property
      See Also:
    • setVmax

      public final void setVmax(double value)
      Sets the value of the vmax property.
      Property description:
      The maximum allowable vvalue for this ScrollPane. Default value is 1.
      Parameters:
      value - the value for the vmax property
      See Also:
    • getVmax

      public final double getVmax()
      Gets the value of the vmax property.
      Property description:
      The maximum allowable vvalue for this ScrollPane. Default value is 1.
      Returns:
      the value of the vmax property
      See Also:
    • vmaxProperty

      public final DoubleProperty vmaxProperty()
      The maximum allowable vvalue for this ScrollPane. Default value is 1.
      Returns:
      the vmax property
      See Also:
    • setFitToWidth

      public final void setFitToWidth(boolean value)
      Sets the value of the fitToWidth property.
      Property description:
      If true and if the contained node is a Resizable, then the node will be kept resized to match the width of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Parameters:
      value - the value for the fitToWidth property
      See Also:
    • isFitToWidth

      public final boolean isFitToWidth()
      Gets the value of the fitToWidth property.
      Property description:
      If true and if the contained node is a Resizable, then the node will be kept resized to match the width of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Returns:
      the value of the fitToWidth property
      See Also:
    • fitToWidthProperty

      public final BooleanProperty fitToWidthProperty()
      If true and if the contained node is a Resizable, then the node will be kept resized to match the width of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Returns:
      the fitToWidth property
      See Also:
    • setFitToHeight

      public final void setFitToHeight(boolean value)
      Sets the value of the fitToHeight property.
      Property description:
      If true and if the contained node is a Resizable, then the node will be kept resized to match the height of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Parameters:
      value - the value for the fitToHeight property
      See Also:
    • isFitToHeight

      public final boolean isFitToHeight()
      Gets the value of the fitToHeight property.
      Property description:
      If true and if the contained node is a Resizable, then the node will be kept resized to match the height of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Returns:
      the value of the fitToHeight property
      See Also:
    • fitToHeightProperty

      public final BooleanProperty fitToHeightProperty()
      If true and if the contained node is a Resizable, then the node will be kept resized to match the height of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.
      Returns:
      the fitToHeight property
      See Also:
    • setPannable

      public final void setPannable(boolean value)
      Sets the value of the pannable property.
      Property description:
      Specifies whether the user should be able to pan the viewport by using the mouse. If mouse events reach the ScrollPane (that is, if mouse events are not blocked by the contained node or one of its children) then pannable is consulted to determine if the events should be used for panning.
      Parameters:
      value - the value for the pannable property
      See Also:
    • isPannable

      public final boolean isPannable()
      Gets the value of the pannable property.
      Property description:
      Specifies whether the user should be able to pan the viewport by using the mouse. If mouse events reach the ScrollPane (that is, if mouse events are not blocked by the contained node or one of its children) then pannable is consulted to determine if the events should be used for panning.
      Returns:
      the value of the pannable property
      See Also:
    • pannableProperty

      public final BooleanProperty pannableProperty()
      Specifies whether the user should be able to pan the viewport by using the mouse. If mouse events reach the ScrollPane (that is, if mouse events are not blocked by the contained node or one of its children) then pannable is consulted to determine if the events should be used for panning.
      Returns:
      the pannable property
      See Also:
    • setPrefViewportWidth

      public final void setPrefViewportWidth(double value)
      Sets the value of the prefViewportWidth property.
      Property description:
      Specify the preferred width of the ScrollPane Viewport. This is the width that will be available to the content node. The overall width of the ScrollPane is the ViewportWidth + padding
      Parameters:
      value - the value for the prefViewportWidth property
      See Also:
    • getPrefViewportWidth

      public final double getPrefViewportWidth()
      Gets the value of the prefViewportWidth property.
      Property description:
      Specify the preferred width of the ScrollPane Viewport. This is the width that will be available to the content node. The overall width of the ScrollPane is the ViewportWidth + padding
      Returns:
      the value of the prefViewportWidth property
      See Also:
    • prefViewportWidthProperty

      public final DoubleProperty prefViewportWidthProperty()
      Specify the preferred width of the ScrollPane Viewport. This is the width that will be available to the content node. The overall width of the ScrollPane is the ViewportWidth + padding
      Returns:
      the prefViewportWidth property
      See Also:
    • setPrefViewportHeight

      public final void setPrefViewportHeight(double value)
      Sets the value of the prefViewportHeight property.
      Property description:
      Specify the preferred height of the ScrollPane Viewport. This is the height that will be available to the content node. The overall height of the ScrollPane is the ViewportHeight + padding
      Parameters:
      value - the value for the prefViewportHeight property
      See Also:
    • getPrefViewportHeight

      public final double getPrefViewportHeight()
      Gets the value of the prefViewportHeight property.
      Property description:
      Specify the preferred height of the ScrollPane Viewport. This is the height that will be available to the content node. The overall height of the ScrollPane is the ViewportHeight + padding
      Returns:
      the value of the prefViewportHeight property
      See Also:
    • prefViewportHeightProperty

      public final DoubleProperty prefViewportHeightProperty()
      Specify the preferred height of the ScrollPane Viewport. This is the height that will be available to the content node. The overall height of the ScrollPane is the ViewportHeight + padding
      Returns:
      the prefViewportHeight property
      See Also:
    • setMinViewportWidth

      public final void setMinViewportWidth(double value)
      Sets the value of the minViewportWidth property.
      Property description:
      Specify the minimum width of the ScrollPane Viewport. This is the width that will be available to the content node.
      Parameters:
      value - the value for the minViewportWidth property
      Since:
      JavaFX 8u40
      See Also:
    • getMinViewportWidth

      public final double getMinViewportWidth()
      Gets the value of the minViewportWidth property.
      Property description:
      Specify the minimum width of the ScrollPane Viewport. This is the width that will be available to the content node.
      Returns:
      the value of the minViewportWidth property
      Since:
      JavaFX 8u40
      See Also:
    • minViewportWidthProperty

      public final DoubleProperty minViewportWidthProperty()
      Specify the minimum width of the ScrollPane Viewport. This is the width that will be available to the content node.
      Returns:
      the minViewportWidth property
      Since:
      JavaFX 8u40
      See Also:
    • setMinViewportHeight

      public final void setMinViewportHeight(double value)
      Sets the value of the minViewportHeight property.
      Property description:
      Specify the minimum height of the ScrollPane Viewport. This is the height that will be available to the content node.
      Parameters:
      value - the value for the minViewportHeight property
      Since:
      JavaFX 8u40
      See Also:
    • getMinViewportHeight

      public final double getMinViewportHeight()
      Gets the value of the minViewportHeight property.
      Property description:
      Specify the minimum height of the ScrollPane Viewport. This is the height that will be available to the content node.
      Returns:
      the value of the minViewportHeight property
      Since:
      JavaFX 8u40
      See Also:
    • minViewportHeightProperty

      public final DoubleProperty minViewportHeightProperty()
      Specify the minimum height of the ScrollPane Viewport. This is the height that will be available to the content node.
      Returns:
      the minViewportHeight property
      Since:
      JavaFX 8u40
      See Also:
    • setViewportBounds

      public final void setViewportBounds(Bounds value)
      Sets the value of the viewportBounds property.
      Property description:
      The actual Bounds of the ScrollPane Viewport. This is the Bounds of the content node.
      Parameters:
      value - the value for the viewportBounds property
      See Also:
    • getViewportBounds

      public final Bounds getViewportBounds()
      Gets the value of the viewportBounds property.
      Property description:
      The actual Bounds of the ScrollPane Viewport. This is the Bounds of the content node.
      Returns:
      the value of the viewportBounds property
      See Also:
    • viewportBoundsProperty

      public final ObjectProperty<Bounds> viewportBoundsProperty()
      The actual Bounds of the ScrollPane Viewport. This is the Bounds of the content node.
      Returns:
      the viewportBounds property
      See Also:
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getControlCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Gets the unmodifiable list of the control's CSS-styleable properties.
      Overrides:
      getControlCssMetaData in class Control
      Returns:
      the unmodifiable list of the control's CSS-styleable properties
      Since:
      JavaFX 8.0
    • getInitialFocusTraversable

      protected Boolean getInitialFocusTraversable()
      Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. This method is overridden as by default UI controls have focus traversable set to true, but that is not appropriate for this control.
      Overrides:
      getInitialFocusTraversable in class Control
      Returns:
      the initial focus traversable state of this control
      Since:
      9