Cursor API

Werner Lehmann lehmann at
Tue Apr 16 02:21:56 PDT 2013


I am currently implementing drag/drop in my little SceneBuilder clone 
(sort of) and came across some oddities in the cursor API:

1. Seemingly no way to get the current cursor. Scene.cursor is null 
unless set before. I guess it defines a fallback if some node does not 
set the cursor. The documentation is a bit short.

2. Seemingly no central place to set/override the current cursor. For 
drag and drop (simple P.D.R.) I am changing the cursor of the drag 
target, and am restoring it after the drag. Is it supposed to work like 

Similar problem: on textfields the cursor is TEXT. In my scenario, a 
click starts a drag or selects the control. It does not focus the 
control to start editing. Again, it would be nice to be able to set a 
DEFAULT cursor in a central place instead of changing it on every 
(textfield) control, only to restore it at some later time. Is it possible?

3. During the drag I want to display a drag hint (current position) 
under/below the cursor. However, the stock cursors (Cursor.MOVE etc) are 
no ImageCursors. How to get the hotspot and cursor size in these cases 
so that I can relocate the hint accordingly? Especially since cursor 
size seems to be platform-specific.

4. Particularly for the 8 sizing cursors (E_RESIZE etc) it is useful to 
work with switch statements on a cursor type enum - instead of else-if 
chains with equals or instanceof. Why is 
com.sun.javafx.cursor.CursorType inaccessible? Basically I had to copy 
the enum...

5. Small typo (missing m in platform):
com.sun.javafx.cursor.CursorFrame.setPlatforCursor(Class<T>, T)

In spite of the above I have to say I am quite pleased with how smooth 
it is to implement this kind of thing so far, talking about the 
SceneBuilder clone. There are rough edges and I have ton of todos. But I 
particularly like how a scene graph makes this easier, for example 
showing a drag selection rectangle - no more XORing. And the drag/drop 
events (DRAG_DETECTED, DRAGGED, MOUSE_RELEASED) are also quite useful - 
I can focus on the logic, not the mouse handling.


More information about the openjfx-dev mailing list