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

knutf

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


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:

B4X:
#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.
    MainForm.Show
   
    Dim Event As Object = AsJavaObject(Label1).CreateEvent("javafx.event.EventHandler","DragDetected",Null)
    AsJavaObject(Label1).RunMethod("setOnDragDetected",Array(Event))

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

    Event = AsJavaObject(Label3).CreateEvent("javafx.event.EventHandler","MouseDragEntered",Null)
    AsJavaObject(Label3).RunMethod("setOnMouseDragEntered",Array(Event))
   
    Event = AsJavaObject(Label3).CreateEvent("javafx.event.EventHandler","MouseDragExited",Null)
    AsJavaObject(Label3).RunMethod("setOnMouseDragExited",Array(Event))
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
    AsJavaObject(lLabel).RunMethod("startFullDrag",Null)
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
 

Attachments

Top