B4J Question Disable resize on form / layout

TheRealMatze

Active Member
Licensed User
Hey there,
i can´t find the command to make a layout fixed. I want to show it in the middle of the screen with a fixed height and width - how can i do that? I use b4xpages.

Thanks
Matze
 

Magma

Expert
Licensed User
Longtime User
Hi there...

is the same way like B4J simple forms....... but need to use it like that B4XPages.GetNativeParent(Me):

didn't try it... but i think will do the job

B4X:
    Dim resol As AWTRobot 'need this lib too...
    Dim resolut() As Int
    Dim scrnW As Double
    Dim scrnH As Double
....
at a sub....

    'Let's get resolution
    resolut= resol.ScreenGetDimensions
    scrnW = resolut(0)
    scrnH = resolut(1)

                        B4XPages.GetNativeParent(Me).top=(scrnH/2)-B4XPages.GetNativeParent(Me).WindowHeight/2
                        B4XPages.GetNativeParent(Me).left=(scrnW/2)-B4XPages.GetNativeParent(Me).WindowWidth/2

    'Disable resize:
B4XPages.GetNativeParent(Me).Resizable=False

ps: may be need at .top to minus... the taskbar height -50dip or -60dip... it's on you :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I do not really understand what you want to do and what exactly you expect.
Is it B4J only, then resize the form.
Is it cross-platform, you can define your layout on a Panel and center it horizontally and vertically to the middle of the screen.
 
Upvote 0

TheRealMatze

Active Member
Licensed User
B4XPages.GetNativeParent(Me).Resizable=False
B4XPages.GetNativeParent(Me).WindowTop=(scrnH/2)-B4XPages.GetNativeParent(Me).WindowHeight/2
B4XPages.GetNativeParent(Me).WindowLeft=(scrnW/2)-B4XPages.GetNativeParent(Me).WindowWidth/2

That works so far, but when the window opens it starts at the wrong position and then "jumps" to the correct one. Is there any way to fix it?
Also the resize of the Window is visible... B4XPages.GetNativeParent(Me).WindowWidth=1200
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
@TheRealMatze I am not so sure because not standing in front of a B4J ide... if you put them into sub Initialize... or if you have a sub for example setup...
first call initialize, then setup (with all goodies), and then showpage...

..Also the resize of the Window is visible...
Do you mean the icon at upper-right ?
You must change the style of form...
 
Last edited:
Upvote 0

TheRealMatze

Active Member
Licensed User
It´s the MainForm.show... I´ve changed the "Main" to

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim resol As AWTRobot 'need this lib too...
    Dim resolut() As Int
    Dim scrnW As Double
    Dim scrnH As Double
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    
    resolut= resol.ScreenGetDimensions
    scrnW = resolut(0)
    scrnH = resolut(1)
    MainForm.WindowLeft=(scrnW/2)-MainForm.Width/2
    MainForm.WindowTop=(scrnH/2)-MainForm.Height/2
    MainForm.Resizable=False
    MainForm.Show
    
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub

that works flicker free - as long as i use one screen size... Or is this a bad idea?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
i think you can use any screen size... why to be bad idea ?

(if you mean if change screen size during the runtime... you can do checks if you want with timer... if screen size changed... but as i know... almost none app do that... why to do it)
 
Upvote 0
Top