With JDK 9 my swing app works well on Windows with 4k highdpi and normal 1080p normal dpi. Labels, Comboboxes etc. all look nice and are scaled up on the 4k screen. But so is my JPanel where i draw custom images. Can i disable the scaling for this one JPanel to handle drawing myself? I am using apache-commons bicubic interpolation to draw more details on the higher unscaled resolution, but as it is scaled out of the box, i just have the "normal" dimensions to draw.
Kind regards
The scaling in Java 9 seems to work like this: Your paint(Component)() methods receive a Graphics2D object which is already scaled. Additionally, the component sizes (e.g. myJFrame.setSize(), myJPanel.getWidth()) are scaled invisibly to the program, meaning that when you say setSize(800,600) on a 200% desktop, the component will be 1600x1200 but getWidth/getHeight will return 800/600.
To "reset" your Graphics object to scaling 1, do this:
To get the correct dimensions, e.g. for filling the whole background with blackness before drawing:
If you do it like this, you should get the desired result on Java 9 and Java 8.
I just created a class for Java devs who strive for a more custom Component design and/or raw drawing, where the system's display scaling should be known and manual scaling is often necessary. It should solve all scaling problems on Java 8 and Java 9. Here it is: