Return to site

Gui scaling has been clipped

broken image
broken image

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. If you do it like this, you should get the desired result on Java 9 and Java 8.

broken image

for filling the whole background with blackness before drawing: final int w = (int) Math.round(getWidth() * scaling)

broken image

To 'reset' your Graphics object to scaling 1, do this: final Graphics2D g = (Graphics2D) graphics įinal AffineTransform t = g.getTransform() įinal double scaling = t.getScaleX() // Assuming square pixels :P tSize(), 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.Ĭan i disable the scaling for this one JPanel to handle drawing myself? The scaling in Java 9 seems to work like this: Your paint(Component)() methods receive a Graphics2D object which is already scaled. Comments may not be up to date, but is more production-code worthy now.) (EDIT: Pasted new version from my library in the form that resulted after about 2 years of use.