B4J Question Detect mainform has moved

Douwe Siegersma

Member
Licensed User
Hello,

Is there a way to detect the mainform has moved?
I tried mainform_MouseReleased but that does not work on the titlebar.
Regards,

Douwe
 

stevel05

Expert
Licensed User
Longtime User
B4X:
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) As Object
    Dim F As Form = Sender
    Log("Form moved " & F.WindowLeft & " : " & F.WindowTop)
End Sub

Note: there is an 8px background border outset on the form in which is displayed the drop shadow. So positioning at the absolute top and left of the screen (or Maximizing the window) will result in a values ot -8,-8 being returned.
 
Upvote 0

Douwe Siegersma

Member
Licensed User
Hello,

Just tried it and it works like a charm!!
I use jCustomComboBox and when it is dropped down and the window is moved, the combobox stays behind.
Now it moves along with the main window. Thanks again.
Regards,

Douwe
 
Upvote 0
Top