B4J Question How to change cursor when mouse drag over a node?


Licensed User
I have made a small test app to demonstrate my problem, the layout contains 3 labels like this:

A DragDetected event is registered with Label1 by using JavaObject
In the DragDetected event the startFullDrag methode on Label1 is run by using JavaObject

MouseDragEntered and MouseDragExited events is registered with Label2 and Label3
In the MouseDragEntered and -Exited events the MouseCursor property is set to CROSSHAIR and DEFAULT, respectively

My problem is that the mouse cursor never changes to crosshair. What am I doing wrong?

The test app is attached to the project

The full code is following:

#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    Dim Event As Object = AsJavaObject(Label1).CreateEvent("javafx.event.EventHandler","DragDetected",Null)

    Event = AsJavaObject(Label2).CreateEvent("javafx.event.EventHandler","MouseDragEntered",Null)
    Event = AsJavaObject(Label2).CreateEvent("javafx.event.EventHandler","MouseDragExited",Null)

    Event = AsJavaObject(Label3).CreateEvent("javafx.event.EventHandler","MouseDragEntered",Null)
    Event = AsJavaObject(Label3).CreateEvent("javafx.event.EventHandler","MouseDragExited",Null)
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub DragDetected_Event(MethodName As String,Args() As Object)
    Dim lLabel As Label = Sender
End Sub

Sub MouseDragEntered_Event(MethodName As String,Args() As Object)
    Dim lLabel As Label = Sender
    lLabel.MouseCursor = fx.Cursors.CROSSHAIR
End Sub

Sub MouseDragExited_Event(MethodName As String,Args() As Object)
    Dim lLabel As Label = Sender
    lLabel.MouseCursor = fx.Cursors.DEFAULT
End Sub

Private Sub AsJavaObject(JO As JavaObject) As JavaObject
    Return JO
End Sub


  • DragTest.zip
    2.2 KB · Views: 99