B4J Question [SOLVED] Windows screen resolution

jroriz

Active Member
Licensed User
When I change the resolution of my display, using windows config, all open windows (non B4J) automatically adjust their sizes according to the new resolution, except my form created in b4j. I need the form I created also changes its size proportionally to the chosen resolution.
I thought this would happen automatically, no code required.
 

jroriz

Active Member
Licensed User
Are you changing the resolution or the scale (DPI)? Why would the windows change their sizes when you change the resolution?
You're right.
I bought a 4k monitor, and what is happening is that when I switch to higher resolutions, windows is changing the DPI.
But all windows change their scales, except the forms created in B4J.
I'll try some compatibility modes...
 
Last edited:

Daestrum

Well-Known Member
Licensed User
You could try
B4X:
 #VirtualMachineArgs: -Dsun.java2d.dpiaware=true
in the project attributes region.

Also something else to look at, if I drag a window to my second screen, it stays roughly the same size even though one res is 1600x900, and the other is 3840x2160. The reason - windows added a % scale to the second screen (in display settings). Setting the scale back to 100% for the second screen makes the window shrink as it crosses the screen division.
 
Last edited:

jroriz

Active Member
Licensed User
Are you changing the resolution or the scale (DPI)? Why would the windows change their sizes when you change the resolution?
You're right.
The scale was at 200% ...
I changed it to 100% and everything is right now.
Just in case, I also used the @Daestrum suggestion.
Thank you all.
 

Intelemarketing

Member
Licensed User
I am running round in circles trying to find a simple way ti get the screen resolution (X,Y)

What is this please ?

" Just in case, I also used the @Daestrum suggestion. "
 

mangojack

Well-Known Member
Licensed User
I am running round in circles trying to find a simple way ti get the screen resolution (X,Y)

Try this ... unsure if there's another method.
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.awt.Toolkit")
jo = jo.RunMethodJO("getDefaultToolkit",Null)

Dim ScreenX As Int = jo.RunMethodJO("getScreenSize",Null).RunMethod("getWidth",Null)
Dim ScreenY As Int = jo.RunMethodJO("getScreenSize",Null).RunMethod("getHeight",Null)
Log($"Screen Resolution =  ${ScreenX}  x  ${ScreenY}"$)

But ... You will get a warning... which in this thread @Erel says is OK and to ignore. If it is any different I am sure he will advise.

** EDIT ... added some missing code.
 
Last edited:

jroriz

Active Member
Licensed User
I am running round in circles trying to find a simple way ti get the screen resolution (X,Y)

What is this please ?

" Just in case, I also used the @Daestrum suggestion. "
You can use AWTRobot:

B4X:
    Dim c As AWTRobot
    Dim a() As Int = c.ScreenGetDimensions
    
    Log("width " & a(0))
    Log("height " & a(1))
 

Intelemarketing

Member
Licensed User
I found this, which adds an important part to solving of the problem - SCALE


SCREEN DIMENSIONS:
    MyScale = GetDeviceLayoutValues.Scale        'divide this into height and width it seems     'This was 2 in my case
    Log ("Scale = " & MyScale)
    MyHeight = GetDeviceLayoutValues.Height   This was twice the width of the Phone   
    Log ("Height = " & MyHeight
    MyWidth = GetDeviceLayoutValues.Width     This was twice the height of the phone
    Log ("Width = " & MyWidth

SCALE gave me a variable to divide into the Height and Width to normalise the size when working with DIP

eg, prefdialog.Initialize(Activity, "Preferences Dialog", 350dip, 350dip)

Thank you for your input
 
Top