You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with amazon corretto java 11 when text is drawn in JPanel using offscreen image (see code below) then use windows display setting to zoom to 150 % the fonts become blurry.
if not using offscreen image, this problem does not happen
if using java 8 this problem does not happen with or without offscreen image
To Reproduce
//Steps and (source) code to reproduce the behavior.//execute the program below using java 11, then use windows 10 display settings to change the zoom to 150%, 1755 ..// note that the fonts are blurry// change the variable useDoubleBuffer to false and execute again, note that the fonts are not blurry//execute again using java 8 , note that fonts are not blurry at 150% or any zoom level importjava.awt.Container;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.Graphics2D;
importjava.awt.Image;
importjava.awt.RenderingHints;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
publicclassBlurryFontextendsJPanel
{
privateImagebufferImage;
privateGraphics2DbufferImageGraphics;
booleanuseDoubleBuffer = true;
publicvoidsetBufferGraphics(Graphics2Dgraphics)
{
bufferImageGraphics = graphics;
}
privatevoidcreateBufferImage(intwidth, intheight)
{
bufferImage = this.createImage(width, height);
}
publicvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
intw = this.getWidth();
inth = this.getHeight();
System.out.println("(w, h)=" + w + " " + h );
createBufferImage(w, h);
setBufferGraphics((useDoubleBuffer) ? (Graphics2D) bufferImage.getGraphics() : (Graphics2D)g);
bufferImageGraphics.setColor(java.awt.Color.blue);
bufferImageGraphics.fillRect(0, 0, getSize().width, getSize().height);
Fontfont = newFont("Lucida Console", 0, 16);
bufferImageGraphics.setFont(font);
bufferImageGraphics.setColor(java.awt.Color.white);
bufferImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
bufferImageGraphics.drawString("Delete All Alarms", 75, 50);
bufferImageGraphics.drawString("A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z", 75, 110);
if (useDoubleBuffer)
{
g.drawImage(bufferImage, 0, 0, null);
}
}
publicstaticvoidmain(String[] args)
{
JFrameframe = newJFrame();
frame.setTitle("Drawing a String");
frame.setSize(1200, 800);
frame.addWindowListener(newWindowAdapter() {
publicvoidwindowClosing(WindowEvente)
{
System.exit(0);
}
});
ContainercontentPane = frame.getContentPane();
BlurryFontp =newBlurryFont();
contentPane.add(p);
frame.setVisible(true);
}
}
Expected behavior
we expect the fonts to be not blurry at 150% windows display setting the same how it was behaving in java 8
Screenshots
here with java 11 fonts are blurry at 150 % windows display settings zoom
here without using offscreen image with java 11 fonts are not blurry at 150% zoom
with java 8 fonts are not blurry at 150% with or without using offscreen image
Platform information
Version: java 11 jdk11.0.18_10
OS: Windows 10
The text was updated successfully, but these errors were encountered:
This is the result of how the HiDPI support was implemented on Windows in JDK9. On macOS, this can be reproduced since JDK8.
The JEP 263 changed the way the AWT/Swing components/frames are rendered on HiDPI monitors, but still maintains some compatibility with the old versions of JDK:
When the application starts the size of any components/frames are still reported the same for low and hidpi screen, in your test the size of the frame is always reported as "1200x800".
Under the hood all native resources are scaled based on the screen dpi, like the native structures for windows, the volatile images/etc. Unfortunately, the raster-based images cannot be scaled in the same way, because that will affect the size reported to the application(like for Bufferredimage).
The problem you faced is caused by the JPanel.createImage(w,h) which creates the raster of the exact size in pixels, and that raster just cannot handle smooth rendering as it has a low dpi.
To solve the problem you can:
replace createImage(w,h) by the createVolatileImage(w,h), or
disable double buffering completely since you render to the SwingDoubleBuffer anyway, or
manually scale the requested "w and h" before passing to the createImage() based on the scalefactor of the monitor, or
Description
with amazon corretto java 11 when text is drawn in JPanel using offscreen image (see code below) then use windows display setting to zoom to 150 % the fonts become blurry.
if not using offscreen image, this problem does not happen
if using java 8 this problem does not happen with or without offscreen image
To Reproduce
Expected behavior
we expect the fonts to be not blurry at 150% windows display setting the same how it was behaving in java 8
Screenshots
here with java 11 fonts are blurry at 150 % windows display settings zoom
here without using offscreen image with java 11 fonts are not blurry at 150% zoom
![image](https://user-images.githubusercontent.com/128389842/226363875-2d3b3e9f-ea60-42a8-887b-52adff5ac0d1.png)
with java 8 fonts are not blurry at 150% with or without using offscreen image
![image](https://user-images.githubusercontent.com/128389842/226364076-ac40935d-6d9d-4c9c-bff1-e2cc62deed04.png)
Platform information
The text was updated successfully, but these errors were encountered: