- java.lang.Object
- 
- java.util.EventObject
- 
- javafx.event.Event
- 
- javafx.scene.input.InputEvent
- 
- javafx.scene.input.GestureEvent
- 
- javafx.scene.input.ScrollEvent
 
 
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable
 
 public final class ScrollEvent extends GestureEvent Scroll event indicates that user performed scrolling by mouse wheel, track pad, touch screen or other similar device.When the scrolling is produced by a touch gesture (such as dragging a finger over a touch screen), it is surrounded by the SCROLL_STARTEDandSCROLL_FINISHEDevents. Changing number of involved touch points during the scrolling is considered a new gesture, so the pair ofSCROLL_FINISHEDandSCROLL_STARTEDnotifications is delivered each time thetouchCountchanges. When the scrolling is caused by a mouse wheel rotation, only a one-timeSCROLLevent is delivered, without the started/finished surroundings. If scrolling inertia is active on the given platform, someSCROLLevents withisInertia()returningtruecan come afterSCROLL_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 deltaXanddeltaYvalues give reasonable results when used as number of pixels to scroll (ThetotalDeltaXandtotalDeltaYcontain the cumulative values for the whole gesture, zeros for mouse wheel). For scrolling text (or other line-based content as tables) thetextDeltavalues should be used if they are available. ThetextDeltaXUnitsandtextDeltaYUnitsdetermine how to interpret thetextDeltaXandtextDeltaYvalues. If the units are set toNONE, 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; }- Since:
- JavaFX 2.0
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classScrollEvent.HorizontalTextScrollUnitsHorizontal text-based scrolling units.static classScrollEvent.VerticalTextScrollUnitsVertical text-based scrolling units.
 - 
Field SummaryFields Modifier and Type Field Description static EventType<ScrollEvent>ANYCommon supertype for all scroll event types.static EventType<ScrollEvent>SCROLLThis event occurs when user performs a scrolling action such as rotating mouse wheel or dragging a finger over touch screen.static EventType<ScrollEvent>SCROLL_FINISHEDThis event occurs when a scrolling gesture ends.static EventType<ScrollEvent>SCROLL_STARTEDThis event occurs when a scrolling gesture is detected.- 
Fields inherited from class javafx.event.Eventconsumed, eventType, NULL_SOURCE_TARGET, target
 - 
Fields inherited from class java.util.EventObjectsource
 
- 
 - 
Constructor SummaryConstructors Constructor Description ScrollEvent(Object source, EventTarget target, 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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult)Constructs new ScrollEvent event.ScrollEvent(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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult)Constructs new ScrollEvent event with null source and targetScrollEvent(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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult)Constructs new ScrollEvent event with null source and target
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description ScrollEventcopyFor(Object newSource, EventTarget newTarget)Creates and returns a copy of this event with the specified event source and target.ScrollEventcopyFor(Object newSource, EventTarget newTarget, EventType<ScrollEvent> type)Creates a copy of the given event with the given fields substituted.doublegetDeltaX()Gets the horizontal scroll amount.doublegetDeltaY()Gets the vertical scroll amount.EventType<ScrollEvent>getEventType()Gets the event type of this event.doublegetMultiplierX()Gets the multiplier used to convert mouse wheel rotation units to pixelsdoublegetMultiplierY()Gets the multiplier used to convert mouse wheel rotation units to pixelsdoublegetTextDeltaX()Gets the horizontal text-based scroll amount.ScrollEvent.HorizontalTextScrollUnitsgetTextDeltaXUnits()Gets the horizontal scrolling units for text-based scrolling.doublegetTextDeltaY()Gets the vertical text-based scroll amount.ScrollEvent.VerticalTextScrollUnitsgetTextDeltaYUnits()Gets the vertical scrolling units for text-based scrolling.doublegetTotalDeltaX()Gets the cumulative horizontal scroll amount for the whole gesture.doublegetTotalDeltaY()Gets the cumulative vertical scroll amount for the whole gesture.intgetTouchCount()Gets number of touch points that caused this event.StringtoString()Returns a string representation of thisScrollEventobject.- 
Methods inherited from class javafx.scene.input.GestureEventgetPickResult, getSceneX, getSceneY, getScreenX, getScreenY, getX, getY, getZ, isAltDown, isControlDown, isDirect, isInertia, isMetaDown, isShiftDown, isShortcutDown
 - 
Methods inherited from class java.util.EventObjectgetSource
 
- 
 
- 
- 
- 
Field Detail- 
ANYpublic static final EventType<ScrollEvent> ANY Common supertype for all scroll event types.
 - 
SCROLLpublic 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_STARTEDpublic static final EventType<ScrollEvent> SCROLL_STARTED This event occurs when a scrolling gesture is detected. It doesn't occur for mouse wheel scrolling.- Since:
- JavaFX 2.2
 
 - 
SCROLL_FINISHEDpublic static final EventType<ScrollEvent> SCROLL_FINISHED This event occurs when a scrolling gesture ends. It doesn't occur for mouse wheel scrolling.- Since:
- JavaFX 2.2
 
 
- 
 - 
Constructor Detail- 
ScrollEventpublic ScrollEvent(Object source, EventTarget target, 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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult) Constructs new ScrollEvent event.- Parameters:
- source- the source of the event. Can be null.
- target- the target of the event. Can be null.
- eventType- The type of the event.
- x- The x with respect to the scene.
- y- The y with respect to the scene.
- screenX- The x coordinate relative to screen.
- screenY- The y coordinate relative to screen.
- shiftDown- true if shift modifier was pressed.
- controlDown- true if control modifier was pressed.
- altDown- true if alt modifier was pressed.
- metaDown- true if meta modifier was pressed.
- direct- true if the event was caused by direct input device. See- GestureEvent.isDirect()
- inertia- if represents inertia of an already finished gesture.
- deltaX- horizontal scroll amount
- deltaY- vertical scroll amount
- totalDeltaX- cumulative horizontal scroll amount
- totalDeltaY- cumulative vertical scroll amount
- textDeltaXUnits- units for horizontal text-based scroll amount
- textDeltaX- horizontal text-based scroll amount
- textDeltaYUnits- units for vertical text-based scroll amount
- textDeltaY- vertical text-based scroll amount
- touchCount- number of touch points
- 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
- Since:
- JavaFX 8.0
 
 - 
ScrollEventpublic ScrollEvent(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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult) Constructs new ScrollEvent event with null source and target- Parameters:
- eventType- The type of the event.
- x- The x with respect to the scene.
- y- The y with respect to the scene.
- screenX- The x coordinate relative to screen.
- screenY- The y coordinate relative to screen.
- shiftDown- true if shift modifier was pressed.
- controlDown- true if control modifier was pressed.
- altDown- true if alt modifier was pressed.
- metaDown- true if meta modifier was pressed.
- direct- true if the event was caused by direct input device. See- GestureEvent.isDirect()
- inertia- if represents inertia of an already finished gesture.
- deltaX- horizontal scroll amount
- deltaY- vertical scroll amount
- totalDeltaX- cumulative horizontal scroll amount
- totalDeltaY- cumulative vertical scroll amount
- textDeltaXUnits- units for horizontal text-based scroll amount
- textDeltaX- horizontal text-based scroll amount
- textDeltaYUnits- units for vertical text-based scroll amount
- textDeltaY- vertical text-based scroll amount
- touchCount- number of touch points
- pickResult- pick result. Can be null, in this case a 2D pick result without any further values is constructed based on the scene coordinates
- Since:
- JavaFX 8.0
 
 - 
ScrollEventpublic ScrollEvent(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.HorizontalTextScrollUnits textDeltaXUnits, double textDeltaX, ScrollEvent.VerticalTextScrollUnits textDeltaYUnits, double textDeltaY, int touchCount, PickResult pickResult) Constructs new ScrollEvent event with null source and target- Parameters:
- eventType- The type of the event.
- x- The x with respect to the scene.
- y- The y with respect to the scene.
- screenX- The x coordinate relative to screen.
- screenY- The y coordinate relative to screen.
- shiftDown- true if shift modifier was pressed.
- controlDown- true if control modifier was pressed.
- altDown- true if alt modifier was pressed.
- metaDown- true if meta modifier was pressed.
- direct- true if the event was caused by direct input device. See- GestureEvent.isDirect()
- inertia- if represents inertia of an already finished gesture.
- deltaX- horizontal scroll amount
- deltaY- vertical scroll amount
- totalDeltaX- cumulative horizontal scroll amount
- totalDeltaY- cumulative vertical scroll amount
- multiplierX- an X multiplier used to convert wheel rotations to pixels
- multiplierY- an Y multiplier used to convert wheel rotations to pixels
- textDeltaXUnits- units for horizontal text-based scroll amount
- textDeltaX- horizontal text-based scroll amount
- textDeltaYUnits- units for vertical text-based scroll amount
- textDeltaY- vertical text-based scroll amount
- touchCount- number of touch points
- pickResult- pick result. Can be null, in this case a 2D pick result without any further values is constructed based on the scene coordinates
- Since:
- JavaFX 8.0
 
 
- 
 - 
Method Detail- 
getDeltaXpublic 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, thetextDeltaXandtextDeltaXUnitsvalues should be considered first.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 Xcoordinate.- Returns:
- Number of pixels to scroll horizontally
 
 - 
getDeltaYpublic 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, thetextDeltaYandtextDeltaYUnitsvalues should be considered first.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 Ycoordinate.- Returns:
- Number of pixels to scroll vertically
 
 - 
getTotalDeltaXpublic 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 Xcoordinate.- Returns:
- Number of pixels scrolled horizontally during the gesture
- Since:
- JavaFX 2.2
 
 - 
getTotalDeltaYpublic 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 Ycoordinate.- Returns:
- Number of pixels to scrolled vertically during the gesture
- Since:
- JavaFX 2.2
 
 - 
getTextDeltaXUnitspublic ScrollEvent.HorizontalTextScrollUnits getTextDeltaXUnits() Gets the horizontal scrolling units for text-based scrolling. The returned value indicates how to interpret thegetTextDeltaX()value. If the returned value isNONE, the text-based scrolling value is not available and the pixel-basedgetDeltaX()value needs to be used.- Returns:
- the horizontal scrolling units for text-based scrolling
 
 - 
getTextDeltaYUnitspublic ScrollEvent.VerticalTextScrollUnits getTextDeltaYUnits() Gets the vertical scrolling units for text-based scrolling. The returned value indicates how to interpret thegetTextDeltaY()value. If the returned value isNONE, the text-based scrolling value is not available and the pixel-basedgetDeltaY()value needs to be used.- Returns:
- the vertical scrolling units for text-based scrolling
 
 - 
getTextDeltaXpublic double getTextDeltaX() Gets the horizontal text-based scroll amount. This value should be interpreted according to thegetTextDeltaXUnits()value.- Returns:
- Number of units to scroll horizontally, zero if the text-based
 horizontal scrolling data is not available getTextDeltaXUnits()returnsNONE
 
 - 
getTextDeltaYpublic double getTextDeltaY() Gets the vertical text-based scroll amount. This value should be interpreted according to thegetTextDeltaYUnits()value.- Returns:
- Number of units to scroll vertically, zero if the text-based
 vertical scrolling data is not available getTextDeltaYUnits()returnsNONE
 
 - 
getTouchCountpublic 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.- Returns:
- Number of touch points that caused this event
- Since:
- JavaFX 2.2
 
 - 
getMultiplierXpublic double getMultiplierX() Gets the multiplier used to convert mouse wheel rotation units to pixels- Returns:
- the x multiplier
- Since:
- JavaFX 8.0
 
 - 
getMultiplierYpublic double getMultiplierY() Gets the multiplier used to convert mouse wheel rotation units to pixels- Returns:
- the y multiplier
- Since:
- JavaFX 8.0
 
 - 
toStringpublic String toString() Returns a string representation of thisScrollEventobject.- Overrides:
- toStringin class- GestureEvent
- Returns:
- a string representation of this ScrollEventobject.
 
 - 
copyForpublic ScrollEvent copyFor(Object newSource, EventTarget newTarget) Description copied from class:GestureEventCreates and returns a copy of this event with the specified event source and target. If the source or target is set tonull, it is replaced by theNULL_SOURCE_TARGETvalue.- Overrides:
- copyForin class- GestureEvent
- Parameters:
- newSource- the new source of the copied event
- newTarget- the new target of the copied event
- Returns:
- the event copy with the new source and target
 
 - 
copyForpublic ScrollEvent copyFor(Object newSource, EventTarget newTarget, EventType<ScrollEvent> type) Creates a copy of the given event with the given fields substituted.- Parameters:
- newSource- the new source of the copied event
- newTarget- the new target of the copied event
- type- the new eventType
- Returns:
- the event copy with the fields substituted
- Since:
- JavaFX 8.0
 
 - 
getEventTypepublic EventType<ScrollEvent> getEventType() Description copied from class:EventGets the event type of this event. Objects of the sameEventclass can have different event types. These event types further specify what kind of event occurred.- Overrides:
- getEventTypein class- GestureEvent
- Returns:
- the event type
 
 
- 
 
-