B4J Question |[SOLVED] How to set a form's minimum size?

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

I want my form to resizable but withing limits... lets say from 600 to screen Width....

I know I can just check the screen width in the resize event, but that wont stop neither the flickering not the screen resizing event from retriggering...

Anyway to avoid this?

EDIT:
There is a "setWindowSizeLimits" method available!!!
my Solution:
Dim ps As Screen = fx.PrimaryScreen
MainForm.SetWindowSizeLimits(600,600, ps.MaxX,ps.MaxY)
 
Last edited:

PaulMeuris

Active Member
Licensed User
With B4XPages you can get the MainPage to resize like this:
B4X:
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim ps As Screen = fx.PrimaryScreen
    Log(ps.MaxX & " " & ps.MaxY)
    B4XPages.GetNativeParent(B4XPages.MainPage).SetWindowSizeLimits(600,600, ps.MaxX,ps.MaxY)
End Sub
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    Log(Width & " " & Height)
End Sub
But the result is not what you would expect:
Waiting for debugger to connect...
Program started.
*** mainpage: B4XPage_Created
1366 728
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
600 600
*** mainpage: B4XPage_Resize [mainpage]
597 600
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
584 581
584 579
584 576
584 572
584 565
584 561
*** mainpage: B4XPage_Resize [mainpage]
1366 705
*** mainpage: B4XPage_Disappear [mainpage]
It seems you can resize below the given limits.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Assuming this is B4j only, you can use:
B4X:
    Dim Form As Form = B4XPages.GetNativeParent(Me)
    Dim Stage As JavaObject = Form.As(JavaObject).GetFieldJO("stage")
    Stage.RunMethod("setMinWidth",Array(600.0))
    Stage.RunMethod("setMinHeight",Array(600.0))
    Dim PS As Screen = fx.PrimaryScreen
    Stage.RunMethod("setMaxWidth",Array(PS.MaxX))
    Stage.RunMethod("setMaxHeight",Array(PS.MaxY))
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
By using these methods the width and height set are for the clientwindow only not including the titlebar and boundary width or the whole window/form?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I haven't measured it, but as it's targeting the stage I would imagine it excludes the borders and title bar, yes.
 
Upvote 0
Top