B4J Question Warning about using the getScreenSize command

nima66

Member
I want to publish the application.
The warning in the report is worrying me.
The height of the form must be from the top to the taskbar, the width must be 75% of the height of the form.
The only way is to use the getScreenSize command.
I get the height of the entire screen and then subtract the height of the taskbar from it
Is there another way?
Warning in the report:
B4X:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by anywheresoftware.b4j.object.JavaObject (file:/D:/Nima/source/club/game%20club%20time%20(windows)/Objects/club.jar) to method sun.awt.SunToolkit.getScreenSize()
WARNING: Please consider reporting this to the maintainers of anywheresoftware.b4j.object.JavaObject
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

I also used the MaxX and MaxY commands of the fx.PrimaryScreen command. But the height it gives is strange.
It neither gives the height of the entire screen nor the height of the taskbar!
Screenshot of the output of using fx.PrimaryScreen

fx.PrimaryScreen.jpg
 

nima66

Member
At all resolutions, the difference between fx.PrimaryScreen.MaxY and jo.RunMethodJO("getScreenSize",Null).RunMethod("getHeight",Null) is always 40.
I don't know if it's like this on all computers and Windows.
Because we can add 40 to the value of fx.PrimaryScreen.MaxY
For me, the taskbar height is always 69 at all resolutions.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Could you upload a small project for your question?
 
Upvote 0

nima66

Member
Worth testing with Java 19. Link here: https://www.b4x.com/b4a.html

I guess that it will work.
I downloaded Java 19 from the link.
It gives an error while compiling.

B4X:
B4J Version: 10.00
Parsing code.    (0.40s)
    Java Version: 19
Building folders structure.    (0.04s)
Compiling code.    (0.22s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
error: module not found: javafx.swing
1 error
only showing the first 1 errors, of 6 total; use -Xmaxerrs if you would like to see more

javac 19.0.2
 
Upvote 0

nima66

Member
Could you upload a small project for your question?
I didn't write any special code.
I get the position of the form with the getFormPosition function.
In the Java code, I added the values 29 and 69 to the taskbar height because the height value it gave was not correct !!

B4X:
Sub getFormPosition As String
    Private screenXY() As String = Regex.Split(",", getScreenWH)
    Private taskbarHeight As Int = getTaskbarHeight
    Private l, t, w, h As Int
    h=screenXY(1)-taskbarHeight
    w=h*0.75
    t=0
    l=(screenXY(0)-w)/2
    Return l & "," & t & "," & w & "," & h
End Sub
Sub getScreenWH As String
    'Private fx As JFX
    'Private ScreenX As Int = fx.PrimaryScreen.MaxX
    'Private ScreenY As Int =  fx.PrimaryScreen.MaxY
    'Return ScreenX & "," & ScreenY

    Dim jo As JavaObject
    jo.InitializeStatic("java.awt.Toolkit")
    jo = jo.RunMethodJO("getDefaultToolkit",Null)
    Private ScreenX As Int = jo.RunMethodJO("getScreenSize",Null).RunMethod("getWidth",Null)
    Private ScreenY As Int =  jo.RunMethodJO("getScreenSize",Null).RunMethod("getHeight",Null)
    Return ScreenX & "," & ScreenY
End Sub
Sub getTaskbarHeight As Int
    Dim jo As JavaObject=Me
    Return jo.RunMethod("taskbar",Null)
End Sub

#if java
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.RECT;
import com.sun.jna.platform.win32.WinDef.HWND;
    public static int taskbar() {
        User32 user32 = User32.INSTANCE;
        HWND hWnd = user32.FindWindow("Shell_TrayWnd", null);
        if (hWnd != null) {
            RECT rect = new RECT();
            user32.GetWindowRect(hWnd, rect);
            int x = rect.left;
            int y = rect.top;
            int width = rect.right - rect.left;
            int height = rect.bottom - rect.top;
            return height+29;
        }
        return 69;
    }
#End If
 
Upvote 0

nima66

Member
Worth testing with Java 19. Link here: https://www.b4x.com/b4a.html

I guess that it will work.
Because I am using the link below to create a PDF file and the following code is used.
B4X:
fUtils.InitializeStatic("javafx.embed.swing.SwingFXUtils")
Apparently there is no such package in JDK 19!
B4X:
Error generating Java code during compilation
Error: Module not found: javafx.swing
 
Upvote 0

teddybear

Well-Known Member
Licensed User
According to testing, it has nothing to do with the project. However, it displays the following error:
module not found: javafx.swing
1.It's obvious that you haven't installed JDK19 +javafx correctly
2.Don't worry about the warnings,the below is the solution

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by anywheresoftware.b4j.object.JavaObject (file:/D:/Nima/source/club/game%20club%20time%20(windows)/Objects/club.jar) to method sun.awt.SunToolkit.getScreenSize()
WARNING: Please consider reporting this to the maintainers of anywheresoftware.b4j.object.JavaObject
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
There is no warning for using java8.
or add JVM args for java 11+
B4X:
#VirtualMachineArgs:--add-exports=java.desktop/sun.awt=ALL-UNNAMED
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I think Erel would have brought it up if it had anything to do with my problem.
Erel is very busy and we cannot expect him to immediately list all possible (existing) solutions to every question in this forum.

Look, your challenge is to let go of things that do not work flawlessly, so that you can be creative with existing solution(s) that you can reuse to solve your challenge. The example in DDD-script shows how you can flawlessly reduce and enlarge a screen display using DDD-script. How does DDD-script deal with your observations? What does it matter if the end result flawlessly meets your expectations? What stops you from replacing the components in the example with two panels, the top of which is 40% and the bottom 60% of the screen height, but can be scaled without any problems using DDD-script? I suspect (without an example program) that is what you want. Let us know the result and if it does not work, post an example program so that we can see what is going wrong.
 
Upvote 0

nima66

Member
1.It's obvious that you haven't installed JDK19 correctly

1.It's obvious that you haven't installed JDK19 correctly
2.Don't worry about the warnings,the below is the solution


There is no warning for using java8.
or add JVM args for java 11+
B4X:
#VirtualMachineArgs:--add-exports=java.desktop/sun.awt=ALL-UNNAMED
Thanks
The warnings have been removed.
But in general, in all versions of Java, it is not possible to get the exact height to the top of the taskbar.
You must manually increase or decrease the value, which is not logical and correct.
 
Upvote 0

nima66

Member
Erel is very busy and we cannot expect him to immediately list all possible (existing) solutions to every question in this forum.

Look, your challenge is to let go of things that do not work flawlessly, so that you can be creative with existing solution(s) that you can reuse to solve your challenge. The example in DDD-script shows how you can flawlessly reduce and enlarge a screen display using DDD-script. How does DDD-script deal with your observations? What does it matter if the end result flawlessly meets your expectations? What stops you from replacing the components in the example with two panels, the top of which is 40% and the bottom 60% of the screen height, but can be scaled without any problems using DDD-script? I suspect (without an example program) that is what you want. Let us know the result and if it does not work, post an example program so that we can see what is going wrong.
I have no problem with dividing and scaling forms and panels.
I just want the height of the form to be exactly to the top of the taskbar.
That is, the bottom of the form should be exactly tangent to the taskbar
This is not done correctly in Java, but in C# and ... it is one of the simplest possible codes!
 
Upvote 0

nima66

Member
After testing on 32 and 64-bit Windows, I came up with the following code and it is currently working properly.

B4X:
Sub getScreenWH As String
    Private taskbarHeight As Int = getObjectHeight("getTaskbarHeight")
    Private getTitleHeight As Int = getObjectHeight("getTitleHeight")
    Private getBorderHeight As Int = getObjectHeight("getBorderHeight")

    Private fx As JFX
    Private ScreenX As Int = fx.PrimaryScreen.MaxX
    Private ScreenY As Int =  (fx.PrimaryScreen.MaxY - getTitleHeight - getBorderHeight - 2dip)
    Return ScreenX & "," & ScreenY
End Sub
 
Upvote 0
Top