B4J Question How to turn off calls to resize event while user is still resizing the window?

lonnieh

Member
Licensed User
Longtime User
As title suggest. For example when the user grabs the window frame, the resize gets called for every pixel difference when dragging the window frame. Is there any way to turn this off and just do it once at the end of the drag, when the user releases the mouse?
 
Solution
Window resizing behavior while the frame is dragging is managed by the operating system and the underlying JavaFX library.
By default, JavaFX enforces real-time resizing, meaning that each pixel of movement triggers a resize event.
It is not possible to completely disable real-time visual resizing without modifying JavaFX's native behavior, which would require more complex solutions in pure Java.

You can intercept the Form_Resize event and use a Timer to process the resizing only after a delay without any new changes.
For example, ResizeTimer is a Timer object that you configure with a short interval (200 ms).
Each call to MainForm_Resize resets the timer. Actual processing only occurs when the user has stopped resizing for the...

Swissmade

Well-Known Member
Licensed User
Longtime User
Maybe using MousePressed and MouseReleased event
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Not sure I follow, I don't think those events are called when the user grabs the window frame but I am not sure
You right was not thinking of that.
Maybe this can help to find a way.

 
Upvote 0

zed

Well-Known Member
Licensed User
Window resizing behavior while the frame is dragging is managed by the operating system and the underlying JavaFX library.
By default, JavaFX enforces real-time resizing, meaning that each pixel of movement triggers a resize event.
It is not possible to completely disable real-time visual resizing without modifying JavaFX's native behavior, which would require more complex solutions in pure Java.

You can intercept the Form_Resize event and use a Timer to process the resizing only after a delay without any new changes.
For example, ResizeTimer is a Timer object that you configure with a short interval (200 ms).
Each call to MainForm_Resize resets the timer. Actual processing only occurs when the user has stopped resizing for the specified interval.
This method does not block visual resizing, but it allows you to defer expensive processing (such as repositioning or recalculating components).
 
Upvote 1
Solution

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ResizeEventIndex As Int
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    ResizeEventIndex = ResizeEventIndex + 1
    Dim MyIndex As Int = ResizeEventIndex
    Sleep(500) 'change interval as needed
    If MyIndex = ResizeEventIndex Then
        Log("resizing done")
    End If
End Sub

More information: [B4X] Resumable subs and the index pattern
 
Upvote 0
Top