Scaling JNLP Breaks on Resolution Change - java

We've been using a jnlp app with computers installed with Java 8. We are attempting to make the app appear as full screen, currently it only shows up in less than half of the screen.
Java 8 does not support this so we've updated to Java 9 and added the following properties to our main jsp file:
<property name="sun.java2d.win.uiScaleX" value="1.88"/>
<property name="sun.java2d.win.uiScaleY" value="1.4"/>
<property name="sun.java2d.dpiaware" value="true"/>
This works quite well in scaling the view, however issues start arising if the desktop resolution is affected in any way. For example, locking the screen and having the screen turn off, or manually changing the resolution or windows scaling, disconnecting\reconnecting an additional screen, or even unplugging the laptop power source will all cause dialogs and popups to only partially display and the top of the app to duplicate visually.
Before:
After:
Before:
After:
I've attempted to update the high DPI settings in java to no effect, both the Program DPI settings and override to no avail. I'm thinking there might need to be some sort of rewriting of the main Java Swing JPanel but I'm not sure.

Related

Java Swing HiDPI Scaling

I have created a program using Java 8 that utilises a Swing GUI in the Eclipse IDE. To scale images and icons to appropriate sizes, it gets and uses the screen resolution. Upon compiling the program within Eclipse, the program displays perfectly fine, and everything seems to operate as it should. However, when I export the project as a "Runnable Jar", and run the program, the image scaling and the program look and feel are all off.
Upon further investigation, it appears that the runnable jar was returning a screen resolution that is exactly 2.5x less then that in eclipse (which is the actual resolution - 3840x2160 vs 1536x864). There is circumstantial evidence across the internet that Java 8 Look and Feels (or something of the sort) don't support HiDPI screen scaling. There are scattered solutions that claim to fix the problem, like updating to Java versions past 8, or by adding arguments to the jar compilation (whatever that means). This is already confusing to a Java novice, and it is only made more confusing by the program being displayed perfectly when run/compiled within the Eclipse IDE.
My question is whether anyone knows how to get a program compiled in Java using Swing to scale correctly on an HiDPI screen, and what the process is that I need to follow to compile a working program?
EDIT 1: Something interesting to note is that in my Windows settings, the "Scale and Layout", "Change the size of text, apps, and other items" is set to exactly 250%, meaning that this setting is obviously the cause of the scaling issues I am encountering. Does someone know how to bypass this setting from within the program, or why it works when I run it through Eclipse?
Java 8 does not support High DPI. On Windows, it runs in DPI unaware mode and relies on Windows to stretch the window bitmap to the scale set for the monitor in the settings. It means the UI of the application looks blurry when displayed on a High DPI monitor.
Later versions of Java, Java 11 and above, support per-monitor High DPI settings. The UI of your application is correctly scale up according to the settings, the text remains crisp. For the icons and images to remain crisp, you should use MultiResolutionImage or its basic implementation BaseMultiResolutionImage to provide higher resolution alternatives.
You should not base your images based on the screen resolution but rather on the scale set for a monitor. For example, a Full HD monitor 1920×1080 with 150% scale has the effective resolution 1280×720, it is the effective resolution that Java reports to you.

Java Swing app looks tiny on high-DPI screen when it should be scaled to normal size

How can I make my Java Swing app GUI scale properly to users on high-DPI screens?
See the screenshot below. At the top you can see how tiny the app looks compared to Ubuntu's file explorer icons and gedit. In the bottom left you can see roughly what size the app should look like (and does look on regular DPI monitors). So I'm looking for a way to scale the GUI of the app properly when a high DPI monitor is in use. For example, gedit looks the same on both regular DPI and high DPI monitors. I want my app to behave like this.
Here is source code for the app: https://github.com/baobabKoodaa/baopass
This is an extremely common problem affecting many apps. Roughly half of the apps I run on Ubuntu are scaled properly without any actions from the user, the other half are not scaled and look really tiny. Note that I'm mainly looking for a solution that doesn't require actions from the user (although any help is appreciated at this point - I haven't found any ways to scale it at all).
According to this scaling should already work out of the box. It doesn't. I'm not sure if this is a bug or if there is some additional step I'm supposed to do besides running the app on Java 9?
You have to tell the drawing libraries to scale the app up.
GDK_SCALE=2 ./application
Will have the appropriate information set in the environment and the widgets will render scaled up such that each pixel effectively takes four pixels of footprint.
Note that the splash screen (if you use Java's splash screen support) isn't presented after the entire Swing libraries are loaded, so it won't scale regardless of the settings you attempt.
In some platforms, like the Linux distribution of Fedora, partial scaling is also possible, such that you can set GDK_SCALE=1.5. Just keep in mind that it's not universally available, and it is not settable to any scaling ratio you might want.
Finally, the older JVMs ignore this setting completely, so if you aren't launching with Java 9 or higher, odds are it won't work. And, of course, the way that things are tweaked for older JVMs and different operating systems tend to vary (if they work at all).
It looks like you're using Linux. You can use a command line switch
java -Dsun.java2d.uiScale=2 -jar some_application.jar
From https://wiki.archlinux.org/index.php/HiDPI#Java_applications

How can I force the size of a Java (.jar) application window?

I have an old .jar file that creates a main window with some textboxes for settings.
The problem is that some textboxes doesn't appear in the window (but they exist), if you lower the computer screen resolution they appear, but with higher resolutions, they disappear.
I tried to decompile the .jar file, but no success...
Since I cannot resize the window in any way (size seems to be fixed), is there a way to force it to be resized or set some Java VM parameters for this purpose?
The loader is "JarRsrcLoader". I attach an image showing the problem in Win10:
(They are not only cut, there are more textboxes).
I asked Mr Google for a Windows tool to make unresizable windows resizeable. Got several matches, here is a short list:
http://www.howtogeek.com/howto/11799/turn-non-resizeable-windows-into-rezieable-windows/
https://www.raymond.cc/blog/how-to-resize-an-unresizable-window-or-dialog-box/
http://www.ghacks.net/2012/06/18/resize-windows-with-fixed-sizes/
I actually found a way to scale the Java application to a lower resolution and see it adequately, only for Linux (but it was what I was searching).
From this source (askubuntu.com): script to fix scaling of java applications.
It provides python scripts to adjust the resolution of certain applications (statically and dynamically) when opened (on a high dpi screen). This solution works for my problem.

Java application drawing strangely

I have a legacy Java application that uses Java 1.3
It works fine on windows Xp but now I need to make it run on windows 7.
I have installed the 1.3 jdk however when it first loads, the app won't render properly. Bits of the screen just show grey background, selecting buttons won't load a new screen etc.
I do know watching the output from the app it just purely graphics not rendering properly.
However if I press "Ctrl-alt-delete" and then just press "cancel" the software runs perfectly.
If I have a second monitor plugged in, it runs perfectly.
Has anyone got any suggestions how to make app run perfectly first time.
Thanks
Firstly, update your java, no excuses not to.
You can try the hack of resizing your component to a different size and then back again. I find this is the best way to make sure that swing doesn't do this sort of mischief with black squares here and there.
These things happen from time to time with non native tools for desktop development as opposed to those specifically designed for the targeted platform.

Java applets and Windows 7 screen DPI setting

I am running Windows 7 and have set the screen DPI setting to a higher value because otherwise text and icons are too small to read on my 1080p monitor. Most programs also can be configured to either adhere to or ignore this setting on an individual basis if needed.
Unfortunately, I am unable to change the DPI for certain (all?) Java programs, such as this one:
http://www.geogebra.org/cms/en/
The program always ignores my screen DPI setting; so the application, fonts, lines, curves, etc. are nearly too small and skinny to be visible. (However, when embedded inside a Web page the applet follows the settings of the browser, and appears OK.)
Anyone know how to fix this problem on my computer or in the program's source code?

Categories