When the scrolling is produced by a touch gesture (such as dragging a finger
over a touch screen), it is surrounded by the SCROLL_STARTED and
SCROLL_FINISHED events. Changing number of involved touch points during
the scrolling is considered a new gesture, so the pair of
SCROLL_FINISHED and SCROLL_STARTED notifications is delivered
each time the touchCount changes. When the scrolling is caused by a mouse
wheel rotation, only a one-time SCROLL event is delivered, without
the started/finished surroundings. If scrolling inertia is active on the
given platform, some SCROLL events with isInertia() returning
true can come after SCROLL_FINISHED.
The event is delivered to the top-most node picked on the gesture coordinates in time of the gesture start - the whole gesture is delivered to the same node even if the coordinates change during the gesture. For mouse wheel rotation the event is delivered to the top-most node picked on mouse cursor location. The delivery is independent of current focus owner.
The event provides two different types of scrolling values: pixel-based and
character/line-based. The basic deltaX and deltaY values
give reasonable results when used as number of pixels
to scroll (The totalDeltaX and totalDeltaY contain the
cumulative values for the whole gesture, zeros for mouse wheel).
For scrolling text (or other line-based content as tables) the
textDelta values should be used if they are available. The
textDeltaXUnits and textDeltaYUnits determine how to
interpret the textDeltaX and textDeltaY values. If the
units are set to NONE, the text-based values are not available
(not provided by the underlying platform) and the pixel-based values
need to be used.
As all gestures, scrolling can be direct (performed directly at the concrete coordinates as on touch screen - the center point among all the touches is usually used as the gesture coordinates) or indirect (performed indirectly as on track pad or with mouse - the mouse cursor location is usually used as the gesture coordinates).
For example, scrolling a graphical node can be achieved by following code:
node.setOnScroll(new EventHandler<ScrollEvent>() {
@Override public void handle(ScrollEvent event) {
node.setTranslateX(node.getTranslateX() + event.getDeltaX());
node.setTranslateY(node.getTranslateY() + event.getDeltaY());
}
});
A scroll event handler on text-based component behaving according to system settings on all platforms should contain following logic:
switch(event.getTextDeltaYUnits()) {
case LINES:
// scroll about event.getTextDeltaY() lines
break;
case PAGES:
// scroll about event.getTextDeltaY() pages
break;
case NONE:
// scroll about event.getDeltaY() pixels
break;
}
| Modifier and Type | Class and Description |
|---|---|
| public static enum | ScrollEvent.
Horizontal text-based scrolling units. |
| public static enum | ScrollEvent.
Vertical text-based scrolling units. |
| Modifier and Type | Field and Description |
|---|---|
| public static final EventType | ANY
Common supertype for all scroll event types.
|
| private final double | |
| private final double | |
| private final double | |
| private final double | |
| public static final EventType | SCROLL
This event occurs when user performs a scrolling action such as rotating mouse wheel or dragging a finger over touch screen. |
| public static final EventType | SCROLL_FINISHED
This event occurs when a scrolling gesture ends. |
| public static final EventType | SCROLL_STARTED
This event occurs when a scrolling gesture is detected. |
| private static final long | |
| private final double | |
| private final ScrollEvent. | |
| private final double | |
| private final ScrollEvent. | |
| private double | |
| private final double | |
| private final int |
| Access | Constructor and Description |
|---|---|
| private | ScrollEvent(Object source, EventTarget target, final EventType<ScrollEvent> eventType, double x, double y, double screenX, double screenY, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean direct, boolean inertia, double deltaX, double deltaY, double totalDeltaX, double totalDeltaY, double multiplierX, double multiplierY, ScrollEvent.
|
| public | ScrollEvent(Object
the source of the event. Can be null. source, EventTarget the target of the event. Can be null. target, final EventType<ScrollEvent> The type of the event. eventType, double The x with respect to the scene. x, double The y with respect to the scene. y, double The x coordinate relative to screen. screenX, double The y coordinate relative to screen. screenY, boolean true if shift modifier was pressed. shiftDown, boolean true if control modifier was pressed. controlDown, boolean true if alt modifier was pressed. altDown, boolean true if meta modifier was pressed. metaDown, boolean true if the event was caused by direct input device. See direct, boolean isDirect()if represents inertia of an already finished gesture. inertia, double horizontal scroll amount deltaX, double vertical scroll amount deltaY, double cumulative horizontal scroll amount totalDeltaX, double cumulative vertical scroll amount totalDeltaY, ScrollEvent.units for horizontal text-based scroll amount textDeltaXUnits,horizontal text-based scroll amount textDeltaX, ScrollEvent.units for vertical text-based scroll amount textDeltaYUnits,vertical text-based scroll amount textDeltaY, int number of touch points touchCount, PickResult pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinates and the target pickResult)Constructs new ScrollEvent event. |
| public | ScrollEvent(final EventType<ScrollEvent>
The type of the event. eventType, double The x with respect to the scene. x, double The y with respect to the scene. y, double The x coordinate relative to screen. screenX, double The y coordinate relative to screen. screenY, boolean true if shift modifier was pressed. shiftDown, boolean true if control modifier was pressed. controlDown, boolean true if alt modifier was pressed. altDown, boolean true if meta modifier was pressed. metaDown, boolean true if the event was caused by direct input device. See direct, boolean isDirect()if represents inertia of an already finished gesture. inertia, double horizontal scroll amount deltaX, double vertical scroll amount deltaY, double cumulative horizontal scroll amount totalDeltaX, double cumulative vertical scroll amount totalDeltaY, ScrollEvent.units for horizontal text-based scroll amount textDeltaXUnits,horizontal text-based scroll amount textDeltaX, ScrollEvent.units for vertical text-based scroll amount textDeltaYUnits,vertical text-based scroll amount textDeltaY, int number of touch points touchCount, PickResult pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinates pickResult)Constructs new ScrollEvent event with null source and target |
| public | ScrollEvent(final EventType<ScrollEvent>
The type of the event. eventType, double The x with respect to the scene. x, double The y with respect to the scene. y, double The x coordinate relative to screen. screenX, double The y coordinate relative to screen. screenY, boolean true if shift modifier was pressed. shiftDown, boolean true if control modifier was pressed. controlDown, boolean true if alt modifier was pressed. altDown, boolean true if meta modifier was pressed. metaDown, boolean true if the event was caused by direct input device. See direct, boolean isDirect()if represents inertia of an already finished gesture. inertia, double horizontal scroll amount deltaX, double vertical scroll amount deltaY, double cumulative horizontal scroll amount totalDeltaX, double cumulative vertical scroll amount totalDeltaY, double an X multiplier used to convert wheel rotations to pixels multiplierX, double an Y multiplier used to convert wheel rotations to pixels multiplierY, ScrollEvent.units for horizontal text-based scroll amount textDeltaXUnits,horizontal text-based scroll amount textDeltaX, ScrollEvent.units for vertical text-based scroll amount textDeltaYUnits,vertical text-based scroll amount textDeltaY, int number of touch points touchCount, PickResult pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinates pickResult)Constructs new ScrollEvent event with null source and target |
| Modifier and Type | Method and Description |
|---|---|
| public ScrollEvent | copyFor(Object
the new source of the copied event newSource, EventTarget the new target of the copied event newTarget)Overrides javafx. Creates and returns a copy of this event with the specified event source and target. |
| public ScrollEvent | Returns: the event copy with the fields substitutedthe new source of the copied event newSource, EventTarget the new target of the copied event newTarget, EventType<ScrollEvent> the new eventType type)Creates a copy of the given event with the given fields substituted. |
| public double | |
| public double | |
| public EventType | getEventType()
Overrides javafx. Gets the event type of this event. |
| public double | Returns: the x multiplierGets the multiplier used to convert mouse wheel rotation units to pixels |
| public double | Returns: the y multiplierGets the multiplier used to convert mouse wheel rotation units to pixels |
| public double | Returns: Number of units to scroll horizontally, zero if the text-based horizontal scrolling data is not availablegetTextDeltaXUnits()
returns NONEGets the horizontal text-based scroll amount. |
| public ScrollEvent. | Returns: the horizontal scrolling units for text-based scrollingGets the horizontal scrolling units for text-based scrolling. |
| public double | Returns: Number of units to scroll vertically, zero if the text-based vertical scrolling data is not availablegetTextDeltaYUnits()
returns NONEGets the vertical text-based scroll amount. |
| public ScrollEvent. | Returns: the vertical scrolling units for text-based scrollingGets the vertical scrolling units for text-based scrolling. |
| public double | Returns: Number of pixels scrolled horizontally during the gestureGets the cumulative horizontal scroll amount for the whole gesture. |
| public double | Returns: Number of pixels to scrolled vertically during the gestureGets the cumulative vertical scroll amount for the whole gesture. |
| public int | Returns: Number of touch points that caused this eventGets number of touch points that caused this event. |
| public String | Returns: a string representation of thisScrollEvent object.Overrides javafx. Returns a string representation of this |
| ANY | back to summary |
|---|---|
| public static final EventType<ScrollEvent> ANY Hides javafx. Common supertype for all scroll event types. | |
| deltaX | back to summary |
|---|---|
private final double deltaX
| |
| deltaY | back to summary |
|---|---|
private final double deltaY
| |
| multiplierX | back to summary |
|---|---|
private final double multiplierX
| |
| multiplierY | back to summary |
|---|---|
private final double multiplierY
| |
| SCROLL | back to summary |
|---|---|
| public static final EventType<ScrollEvent> SCROLL This event occurs when user performs a scrolling action such as rotating mouse wheel or dragging a finger over touch screen. | |
| SCROLL_FINISHED | back to summary |
|---|---|
| public static final EventType<ScrollEvent> SCROLL_FINISHED This event occurs when a scrolling gesture ends. It doesn't occur for mouse wheel scrolling.
| |
| SCROLL_STARTED | back to summary |
|---|---|
| public static final EventType<ScrollEvent> SCROLL_STARTED This event occurs when a scrolling gesture is detected. It doesn't occur for mouse wheel scrolling.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| textDeltaX | back to summary |
|---|---|
private final double textDeltaX
| |
| textDeltaXUnits | back to summary |
|---|---|
private final ScrollEvent.
| |
| textDeltaY | back to summary |
|---|---|
private final double textDeltaY
| |
| textDeltaYUnits | back to summary |
|---|---|
private final ScrollEvent.
| |
| totalDeltaX | back to summary |
|---|---|
private double totalDeltaX
| |
| totalDeltaY | back to summary |
|---|---|
private final double totalDeltaY
| |
| touchCount | back to summary |
|---|---|
private final int touchCount
| |
| ScrollEvent | back to summary |
|---|---|
| private ScrollEvent(Object source, EventTarget target, final EventType<ScrollEvent> eventType, double x, double y, double screenX, double screenY, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean direct, boolean inertia, double deltaX, double deltaY, double totalDeltaX, double totalDeltaY, double multiplierX, double multiplierY, ScrollEvent. | |
| ScrollEvent | back to summary |
|---|---|
| public ScrollEvent(Object source, EventTarget target, final EventType<ScrollEvent> eventType, double x, double y, double screenX, double screenY, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean direct, boolean inertia, double deltaX, double deltaY, double totalDeltaX, double totalDeltaY, ScrollEvent. Constructs new ScrollEvent event.
| |
| ScrollEvent | back to summary |
|---|---|
| public ScrollEvent(final EventType<ScrollEvent> eventType, double x, double y, double screenX, double screenY, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean direct, boolean inertia, double deltaX, double deltaY, double totalDeltaX, double totalDeltaY, ScrollEvent. Constructs new ScrollEvent event with null source and target
| |
| ScrollEvent | back to summary |
|---|---|
| public ScrollEvent(final EventType<ScrollEvent> eventType, double x, double y, double screenX, double screenY, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean direct, boolean inertia, double deltaX, double deltaY, double totalDeltaX, double totalDeltaY, double multiplierX, double multiplierY, ScrollEvent. Constructs new ScrollEvent event with null source and target
| |
| copyFor | back to summary |
|---|---|
| public ScrollEvent copyFor(Object newSource, EventTarget newTarget) Overrides javafx. Doc from javafx. Creates and returns a copy of this event with the specified event source
and target. If the source or target is set to
| |
| copyFor | back to summary |
|---|---|
| public ScrollEvent copyFor(Object newSource, EventTarget newTarget, EventType<ScrollEvent> type) Creates a copy of the given event with the given fields substituted.
| |
| getDeltaX | back to summary |
|---|---|
| public double getDeltaX() Gets the horizontal scroll amount. This value should be interpreted
as a number of pixels to scroll. When scrolling a text-based content,
the
The sign of the value is reversed compared to the coordinate system
(when you scroll right, the content actually needs to go left). So the
returned value can be simply added to the content's
| |
| getDeltaY | back to summary |
|---|---|
| public double getDeltaY() Gets the vertical scroll amount. This value should be interpreted
as a number of pixels to scroll. When scrolling a line-based content,
the
The sign of the value is reversed compared to the coordinate system
(when you scroll down, the content actually needs to go up). So the
returned value can be simply added to the content's
| |
| getEventType | back to summary |
|---|---|
| public EventType Overrides javafx. Doc from javafx. Gets the event type of this event. Objects of the same
| |
| getMultiplierX | back to summary |
|---|---|
| public double getMultiplierX() Gets the multiplier used to convert mouse wheel rotation units to pixels
| |
| getMultiplierY | back to summary |
|---|---|
| public double getMultiplierY() Gets the multiplier used to convert mouse wheel rotation units to pixels
| |
| getTextDeltaX | back to summary |
|---|---|
| public double getTextDeltaX() Gets the horizontal text-based scroll amount. This value should be
interpreted according to the
| |
| getTextDeltaXUnits | back to summary |
|---|---|
| public ScrollEvent. Gets the horizontal scrolling units for text-based scrolling.
The returned value indicates how to interpret the
| |
| getTextDeltaY | back to summary |
|---|---|
| public double getTextDeltaY() Gets the vertical text-based scroll amount. This value should be
interpreted according to the
| |
| getTextDeltaYUnits | back to summary |
|---|---|
| public ScrollEvent. Gets the vertical scrolling units for text-based scrolling.
The returned value indicates how to interpret the
| |
| getTotalDeltaX | back to summary |
|---|---|
| public double getTotalDeltaX() Gets the cumulative horizontal scroll amount for the whole gesture. This value should be interpreted as a number of pixels to scroll relatively to the state at the beginning of the gesture. Contains zeros for mouse wheel scrolling.
The sign of the value is reversed compared to the coordinate system
(when you scroll right, the content actually needs to go left). So the
returned value can be simply added to the content's
| |
| getTotalDeltaY | back to summary |
|---|---|
| public double getTotalDeltaY() Gets the cumulative vertical scroll amount for the whole gesture. This value should be interpreted as a number of pixels to scroll relatively to the state at the beginning of the gesture. Contains zeros for mouse wheel scrolling.
The sign of the value is reversed compared to the coordinate system
(when you scroll down, the content actually needs to go up). So the
returned value can be simply added to the content's
| |
| getTouchCount | back to summary |
|---|---|
| public int getTouchCount() Gets number of touch points that caused this event. For non-touch source devices as mouse wheel and for inertia events after gesture finish it returns zero.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides javafx. Returns a string representation of this | |
| Modifier and Type | Field and Description |
|---|---|
| public static final ScrollEvent. | CHARACTERS
The horizontal text-based scrolling amount is a number of characters to scroll. |
| public static final ScrollEvent. | NONE
The horizontal text-based scrolling data is not available (not provided by the underlying platform). |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ScrollEvent. | |
| public static ScrollEvent. |
| CHARACTERS | back to summary |
|---|---|
| public static final ScrollEvent. The horizontal text-based scrolling amount is a number of characters to scroll. | |
| NONE | back to summary |
|---|---|
| public static final ScrollEvent. The horizontal text-based scrolling data is not available (not provided by the underlying platform). | |
| HorizontalTextScrollUnits | back to summary |
|---|---|
| private HorizontalTextScrollUnits() | |
| valueOf | back to summary |
|---|---|
| public static ScrollEvent. | |
| values | back to summary |
|---|---|
| public static ScrollEvent. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final ScrollEvent. | LINES
The vertical text-based scrolling amount is a number of lines to scroll. |
| public static final ScrollEvent. | NONE
The vertical text-based scrolling data is not available (not provided by the underlying platform). |
| public static final ScrollEvent. | PAGES
The vertical text-based scrolling amount is a number of pages to scroll. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ScrollEvent. | |
| public static ScrollEvent. |
| LINES | back to summary |
|---|---|
| public static final ScrollEvent. The vertical text-based scrolling amount is a number of lines to scroll. | |
| NONE | back to summary |
|---|---|
| public static final ScrollEvent. The vertical text-based scrolling data is not available (not provided by the underlying platform). | |
| PAGES | back to summary |
|---|---|
| public static final ScrollEvent. The vertical text-based scrolling amount is a number of pages to scroll. | |
| VerticalTextScrollUnits | back to summary |
|---|---|
| private VerticalTextScrollUnits() | |
| valueOf | back to summary |
|---|---|
| public static ScrollEvent. | |
| values | back to summary |
|---|---|
| public static ScrollEvent. | |