Module MaterialFX

Class ScrollUtils

java.lang.Object
io.github.palexdev.materialfx.utils.ScrollUtils

public class ScrollUtils extends Object
Utility class for ScrollPanes.
  • Method Details

    • isTrackPad

      public static boolean isTrackPad(ScrollEvent event, ScrollUtils.ScrollDirection scrollDirection)
      Determines if the given ScrollEvent comes from a trackpad.

      Although this method works in most cases, it is not very accurate. Since in JavaFX there's no way to tell if a ScrollEvent comes from a trackpad or a mouse we use this trick: I noticed that a mouse scroll has a delta of 32 (don't know if it changes depending on the device or OS) and trackpad scrolls have a way smaller delta. So depending on the scroll direction we check if the delta is lesser than 10 (trackpad event) or greater(mouse event).
      See Also:
    • determineScrollDirection

      public static ScrollUtils.ScrollDirection determineScrollDirection(ScrollEvent event)
      Determines the scroll direction of the given ScrollEvent.

      Although this method works fine, it is not very accurate. In JavaFX there's no concept of scroll direction, if you try to scroll with a trackpad you'll notice that you can scroll in both directions at the same time, both deltaX and deltaY won't be 0.

      For this method to work we assume that this behavior is not possible.

      If deltaY is 0 we return LEFT or RIGHT depending on deltaX (respectively if lesser or greater than 0).

      Else we return DOWN or UP depending on deltaY (respectively if lesser or greater than 0).

      See Also:
    • addSmoothScrolling

      public static void addSmoothScrolling(ScrollPane scrollPane)
      Adds a smooth scrolling effect to the given scroll pane, calls addSmoothScrolling(ScrollPane, double) with a default speed value of 1.
    • addSmoothScrolling

      public static void addSmoothScrolling(ScrollPane scrollPane, double speed)
      Adds a smooth scrolling effect to the given scroll pane with the given scroll speed. Calls addSmoothScrolling(ScrollPane, double, double) with a default trackPadAdjustment of 7.
    • addSmoothScrolling

      public static void addSmoothScrolling(ScrollPane scrollPane, double speed, double trackPadAdjustment)
      Adds a smooth scrolling effect to the given scroll pane with the given scroll speed and the given trackPadAdjustment.

      The trackPadAdjustment is a value used to slow down the scrolling if a trackpad is used. This is kind of a workaround and it's not perfect, but at least it's way better than before. The default value is 7, tested up to 10, further values can cause scrolling misbehavior.
    • animateScrollBars

      public static void animateScrollBars(ScrollPane scrollPane)
      Adds a fade in and out effect to the given scroll pane's scroll bars, calls animateScrollBars(ScrollPane, double) with a default fadeSpeedMillis value of 500.
    • animateScrollBars

      public static void animateScrollBars(ScrollPane scrollPane, double fadeSpeedMillis)
      Adds a fade in and out effect to the given scroll pane's scroll bars, calls animateScrollBars(ScrollPane, double, double) with a default fadeSpeedMillis value of 500 and a default hideAfterMillis value of 800.
    • animateScrollBars

      public static void animateScrollBars(ScrollPane scrollPane, double fadeSpeedMillis, double hideAfterMillis)
      Adds a fade in and out effect to the given scroll pane's scroll bars with the given fadeSpeedMillis and hideAfterMillis values.
      See Also: