java.lang.Object
io.github.palexdev.materialfx.utils.ScrollUtils
Utility class for ScrollPanes.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSmoothScrolling(ScrollPane scrollPane) Adds a smooth scrolling effect to the given scroll pane, callsaddSmoothScrolling(ScrollPane, double)with a default speed value of 1.static voidaddSmoothScrolling(ScrollPane scrollPane, double speed) Adds a smooth scrolling effect to the given scroll pane with the given scroll speed.static voidaddSmoothScrolling(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.static voidanimateScrollBars(ScrollPane scrollPane) Adds a fade in and out effect to the given scroll pane's scroll bars, callsanimateScrollBars(ScrollPane, double)with a default fadeSpeedMillis value of 500.static voidanimateScrollBars(ScrollPane scrollPane, double fadeSpeedMillis) Adds a fade in and out effect to the given scroll pane's scroll bars, callsanimateScrollBars(ScrollPane, double, double)with a default fadeSpeedMillis value of 500 and a default hideAfterMillis value of 800.static voidanimateScrollBars(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.static ScrollUtils.ScrollDirectionDetermines the scroll direction of the given ScrollEvent.static booleanisTrackPad(ScrollEvent event, ScrollUtils.ScrollDirection scrollDirection) Determines if the given ScrollEvent comes from a trackpad.
-
Method Details
-
isTrackPad
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). -
determineScrollDirection
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).
-
addSmoothScrolling
Adds a smooth scrolling effect to the given scroll pane, callsaddSmoothScrolling(ScrollPane, double)with a default speed value of 1. -
addSmoothScrolling
Adds a smooth scrolling effect to the given scroll pane with the given scroll speed. CallsaddSmoothScrolling(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
Adds a fade in and out effect to the given scroll pane's scroll bars, callsanimateScrollBars(ScrollPane, double)with a default fadeSpeedMillis value of 500. -
animateScrollBars
Adds a fade in and out effect to the given scroll pane's scroll bars, callsanimateScrollBars(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.
-