Class VFXScrollPaneBehavior

java.lang.Object
io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
io.github.palexdev.virtualizedfx.controls.behaviors.VFXScrollPaneBehavior

public class VFXScrollPaneBehavior extends io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
Extension of BehaviorBase and default behavior implementation for VFXScrollPane.

Most of the work related to scrolling is already handled by the scroll bars present in the VFXScrollPaneSkin. This just implements the methods necessary to make the VFXScrollPane.dragToScrollProperty() feature work.

You can fine-tune the VFXScrollPane.dragSmoothScrollProperty() by changing the properties:

- DRAG_SMOOTH_SCROLL_DURATION

- DRAG_SMOOTH_SCROLL_CURVE

- SMOOTH_DRAG_SENSIBILITY (this is basically a multiplier to scroll more/less and make the smooth scroll more significant)

  • Field Details

    • DRAG_SMOOTH_SCROLL_DURATION

      protected Duration DRAG_SMOOTH_SCROLL_DURATION
    • DRAG_SMOOTH_SCROLL_CURVE

      protected Interpolator DRAG_SMOOTH_SCROLL_CURVE
    • SMOOTH_DRAG_SENSIBILITY

      protected double SMOOTH_DRAG_SENSIBILITY
  • Constructor Details

    • VFXScrollPaneBehavior

      public VFXScrollPaneBehavior(VFXScrollPane pane)
  • Method Details

    • withMomentum

      protected io.github.palexdev.mfxeffects.animations.MomentumTransition withMomentum(double delta)
      Convenience method to build a MomentumTransition using MomentumTransition.fromTime(double, double) with the given parameter. Uses DRAG_SMOOTH_SCROLL_DURATION as the duration and DRAG_SMOOTH_SCROLL_CURVE as the interpolator.
    • mousePressed

      public void mousePressed(MouseEvent me)
      Action performed when a MouseEvent.MOUSE_PRESSED event occurs.

      Stores both the mouse position and the scroll values which will be needed by mouseDragged(MouseEvent) to compute how much to scroll if the drag to scroll feature is active.
      Overrides:
      mousePressed in class io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
    • mouseDragged

      public void mouseDragged(MouseEvent me)
      Action performed when a MouseEvent.MOUSE_DRAGGED event occurs.

      Adjusts both the vertical or the horizontal scroll values according to the mouse movement, immediately via setters or with an animation (withMomentum(double)) if the "smooth drag to scroll feature" is active.

      There are several conditions that get checked here:

      1) Exits if either the feature is off or the content is null

      2) Does not allow diagonal scrolling for a more pleasant UX and so the dominant axis is determined by how much the mouse moved vertically and horizontally since the press of the mouse.

      3) The scroll starts only after a certain threshold, by default 16px.

      4) The scroll occurs only if the bar for the determined axis is visible. This is managed by the canVScroll and canHScroll flags. The default skin does not allow the scroll when a bar is hidden, either because the content is smaller than the viewport on its axis or if the policies hide the bar.

      The displacement is computed as follows:

      - mouseX - dragStartX for the horizontal axis

      - mouseY - dragStartY for the vertical axis

      Also, if the values are adjusted by animations, every time one is played the dragStart positions are updated for a better user experience.
      Overrides:
      mouseDragged in class io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
      See Also:
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Action performed when a MouseEvent.MOUSE_RELEASED event occurs.

      Resets the properties needed by mouseDragged(MouseEvent).
      Overrides:
      mouseReleased in class io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
    • keyPressed

      public void keyPressed(KeyEvent ke)
      Action performed when KeyEvent.KEY_PRESSED events occurs.
      Overrides:
      keyPressed in class io.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
    • getViewportSize

      public io.github.palexdev.mfxcore.base.beans.Size getViewportSize()
      See Also:
    • setViewportSize

      public void setViewportSize(io.github.palexdev.mfxcore.base.beans.Size viewportSize)
      This is called by the default skin to make the viewport's size available to the behavior. These values are important for the drag to scroll feature to work properly.
    • isCanVScroll

      public boolean isCanVScroll()
      See Also:
    • setCanVScroll

      public void setCanVScroll(boolean canVScroll)
      This is called by the default skin to make the behavior class aware of the vertical scroll bar's visibility. This information is important for the drag to scroll feature to work properly.
    • isCanHScroll

      public boolean isCanHScroll()
      See Also:
    • setCanHScroll

      public void setCanHScroll(boolean canHScroll)
      This is called by the default skin to make the behavior class aware of the horizontal scroll bar's visibility. This information is important for the drag to scroll feature to work properly.
    • getDragThreshold

      public double getDragThreshold()
      See Also:
    • setDragThreshold

      public void setDragThreshold(double dragThreshold)
      Sets the number of pixels that act as a threshold before the scroll happens on drag.
      See Also: