Why is my JDK11 program affected by Windows 7 personalized display setting? - java

I use Windows 7 and have personalized the display to zoom in to medium setting (125%), making icons on the desktop bigger etc. Now when I changed from jdk8 to jdk11 I discovered the java applications are affected by this. What's going on and how do I avoid this?
So e.g. if I just create a simple JFrame and draw an image to it the frame is bigger than it should be, and the picture looks terrible.

Java 9 introduced support for scaling in high-dpi displays: http://openjdk.java.net/jeps/263
That would explain why you see this behavior change when going from jdk8 to jdk11.
Try the suggestions in this answer: https://stackoverflow.com/a/48623068/701303
(for swing: -Dsun.java2d.uiScale=1.0; for javafx: -Dprism.allowhidpi=false)

Related

Swing looks zoomed after upgrading java

I have a old application running a Swing client. I upgraded from Java 7 to 8 a long time ago. The upgrade went fine. Ever since I have wanted to upgrade to Java 9, then 11 and now 13. However this is where I meet problems.
The UI looks fine and as intended with Java 8, but any newer Java version will somehow change the font sizes and maybe components for some reason. I do not have any pictures to show because the application is maintained on a network without internet access because of security reasons. The client looks like most thing is multiplied with a factor of 2.0 or something. It appears as zoomed or maybe something you would create with universal design in mind. Even the splash screen is doubled in size for some reason and that is an image. There are some exeptions. The title text in the windows is the same. Also text on buttons and lables seems to be equal. Icons, images (splash) and text inside textfields/editors is much larger.
I have tried to find a solution for a long time but have not found anything. I am hoping someone else have experienced this problem or at least know what the problem could be.
Holgers comment about OS scaling was the issue. I have a 4K screen with 150% scaling set in the OS. Putting it back to 100% made the Java Swing Client look the same as when running Java 8.
To override add -Dsun.java2d.uiScale=1
Se also https://superuser.com/questions/988379/how-do-i-run-java-apps-upscaled-on-a-high-dpi-display

java swing aplication components out of place

I have problem with Java application
Components seems to be out of place.
Problems apear only on one computer. Operating system is Windows 10 with anniversary update. I am not sure if it is relevant but one of the other computers i tested application doesnt have anniversary update.
Other thing which makes this computer different is graphic card which is Intel HD graphics 3000 (also not sure if it is relevant).
I am no expert and i feel like child in a fog when i try to solve this issue.
Application is written with java 7 sdk. But it doesnt look good on both jre 7 and 8 on this computer while it looks good with both jre's on every other computer i tested. I am not sure if i am going right direction but setting the environmental variable J2D_D3D_NO_HWCHECK to "true" only made things worse.
I am posting 2 screenshots. First one is from computer where it is misplaced and second one of how it is supposed to look like. It is only one difference of many i can see in application.
UPDATE:
I narrowed down this problem. Gap created in Windows and Windows Classic LookAndFeel is bigger.
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
}
System.out.println(javax.swing.LayoutStyle.getInstance().getPreferredGap(new javax.swing.JLabel(), new javax.swing.JLabel(), javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.SwingConstants.SOUTH, new javax.swing.JPanel()));
Code i provided is giving me 7 or 6 depending on machine. I tried running it on 2 machines with Windows 10 anniversary update both but still i got different results. Changeing LookAndFeel to CrossPlatform fixes problem in this situation. Although it might cause more problems in different panels in application.
I am unable to determine what might be the reason to getting different values from the same class on different computers with the same operating system version.
If anyone is interested i solved this issue
Changing Control Panel > Appearance and Personalisation > Display > Make text and other items larger or smaller
makes default button font size to get bigger. Default button font size is used by windows LookAndFeel to calculate gap size between components in LayoutStyle. LayoutStyle is used as default Layout on all components if one is not set.
Making text larger to 125% caused font size to increase by 2 points. After all math included in Windows LookAndFeel it made default small gap size increase from 6 points to 7.

JavaFX strange rendering on Windows 7

I have just started working with JavaFX and have come to an obstacle. When I open SceneBuilder it renders very strangely. When the window is restored it seems zoomed in, and when maximized it looks better, but still not quite OK and inoperable.
The same goes for HelloWorld example that I created, and examples I found on internet, so I think it is something systemic. I have tried with Java 7u71 and with Java 8u25. No change. Please help if you know how to fix this.
After reading system requirements (http://www.oracle.com/technetwork/java/javafx/downloads/supportedconfigurations-1506746.html) I came across this line:
To avoid rendering issues on Windows platforms, upgrade the ATI driver to Catalyst 11.09 or later.
If you have a old laptop like I do (with ATI FireGL V5200 and ATI driver 8.561.0.0), try to disable HWA. I did this by setting JAVA_TOOL_OPTIONS in Windows Environment variables. See answer: How to disable or bypass Hardware Graphics Acceleration(Prism) in JavaFX
For Java 7: JAVA_TOOL_OPTIONS=-Dprism.order=j2d
For Java 8: JAVA_TOOL_OPTIONS=-Dprism.order=sw

Mac LWJGL Display no maximization option

On windows, my LWJGL application is able to be maximized, as shown here:
Maximization allowed http://img28.imageshack.us/img28/8428/maximize.png
However, the same application on Mac does not allow you to maximize the display, as shown here:
http://img805.imageshack.us/img805/6653/maximization.png
Is there a line of code that I am missing?
I am able to re-size the window manually to fit the whole screen, however, it would be nice to know if it would be possible to enable the maximize button for the sake of ease.
One try would be to use the nightly builds of LWJGL found here:
https://www.newdawnsoftware.com/jenkins/view/LWJGL/job/LWJGL/
If you aren't using it already. It contains many fixes and additions, maybe even for this problem.
Otherwise the changelog from 2.8.3 just states that it got added and there is no line of code manipulating it. Do you have the same version of LWJGL on your mac?

Transparent Swing Windows

I have a little JWindow with a logo on it that users can drag stuff to.
I develop my application mainly on OS X. To get a transparent window i use
setBackground(new Color(0,0,0,0));
On a mac this works beautifully but I can't get the same effect on windows.
Is there any way to get a transparent window without using 1.6 specific features.
I need 1.5 compatibility.
Sadly, windows (previous to Vista at least) doesn't do this kind of compositing. There is however a workaround. Example code can be found at http://rabbit-hole.blogspot.com/2007/02/non-rectangular-windows-update.html
As of 1.5 Java does not support transparent windows.
This feature is introduced as part of 1.6.10 release.
See AWTUtilities class for more details.

Categories

Resources