B4J Question Solved - Event move window??

Ender1969

Member
Licensed User
Hi all,

How to know if the main application window has been moved in B4j? With MainForm_Resize we know if it changed its size, but what event does it fire if the window was moved?

Thanks
 

stevel05

Expert
Licensed User
Longtime User
There is nothing built in to B4j, but you can add a listener to the window x and y properties:

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

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
  
    Dim Stage As JavaObject = MainForm.As(JavaObject).GetField("stage")
  
    Dim Prop As JavaObject = Stage.RunMethod("xProperty",Null)
    Dim O As Object = Prop.CreateEventFromUI("javafx.beans.value.ChangeListener","WindowMoved",Null)
    Prop.RunMethod("addListener",Array(O))
  
    Dim Prop As JavaObject = Stage.RunMethod("yProperty",Null)
    Dim O As Object = Prop.CreateEventFromUI("javafx.beans.value.ChangeListener","WindowMoved",Null)
    Prop.RunMethod("addListener",Array(O))
  
End Sub


Private Sub WindowMoved_Event (MethodName As String, Args() As Object)
    Log(MainForm.WindowLeft & ", " & MainForm.WindowTop)
End Sub

Edit: link below is a better implementation that I had forgotten about.
 
Upvote 0
Top