B4J Question B4J Form Position

How can I get the position of a form when it is in the decorated state relative to the Windows screen, i.e. the distance from the left and top of the screen
Tankyou
 
Wrong direction but right idea, plus it shows how to get the abovementioned Form Object:

 
Upvote 0
OK, so you need to set a listener on the x and y properties of the form. It's not as bad as it sounds try this:

B4X: Copy
Private Sub SetMoveListener(Form As JavaObject)
    Dim Stage As JavaObject = Form.GetField("stage")
    Dim XProp As JavaObject = Stage.RunMethod("xProperty",Null)
    Dim YProp As JavaObject = Stage.RunMethod("yProperty",Null)
   
    Dim O As Object = Form.CreateEventFromUI("javafx.beans.value.ChangeListener","FormMoved",Null)
    XProp.RunMethod("addListener",Array(O))
    YProp.RunMethod("addListener",Array(O))
End Sub

Private Sub FormMoved_Event (MethodName As String, Args() As Object)
    Dim F As Form = Sender
    Log("Form moved " & F.WindowLeft & " : " & F.WindowTop)
End Sub

Usage:

B4X: Copy
SetMoveListener(MainForm)
 
Upvote 0
OK, so you need to set a listener on the x and y properties of the form. It's not as bad as it sounds try this:

B4X: Copy
Private Sub SetMoveListener(Form As JavaObject)
    Dim Stage As JavaObject = Form.GetField("stage")
    Dim XProp As JavaObject = Stage.RunMethod("xProperty",Null)
    Dim YProp As JavaObject = Stage.RunMethod("yProperty",Null)
  
    Dim O As Object = Form.CreateEventFromUI("javafx.beans.value.ChangeListener","FormMoved",Null)
    XProp.RunMethod("addListener",Array(O))
    YProp.RunMethod("addListener",Array(O))
End Sub

Private Sub FormMoved_Event (MethodName As String, Args() As Object)
    Dim F As Form = Sender
    Log("Form moved " & F.WindowLeft & " : " & F.WindowTop)
End Sub

Usage:

B4X: Copy
SetMoveListener(MainForm)
Tankyou som mach my friend's

stevel05​

 
Upvote 0
Back
Top