On Sun, 19 Jul 2026 09:01:11 GMT, Prasanta Sadhukhan <[email protected]> wrote:
>> [JDK-6328248](https://bugs.openjdk.org/browse/JDK-6328248) fixed PrintJob >> (1.1 Graphics API) based JProgressBar printing for most L&F however it seems >> to cause ClassCastException in AquaProgressBarUI.paint as non-Graphics2D >> path was not handled >> `Caused by: java.lang.ClassCastException: class sun.print.ProxyPrintGraphics >> cannot be cast to class java.awt.Graphics2D (sun.print.ProxyPrintGraphics >> and java.awt.Graphics2D are in module java.desktop of loader 'bootstrap') ` >> >> FIx is made to render Aqua progress bar into BufferedImage, then drawImage >> for non-Graphics2D case where 1.1 PrintJob is used >> >> >> >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Prasanta Sadhukhan has updated the pull request incrementally with one > additional commit since the last revision: > > Move paintString block to paint I haven't tested it (I'll leave you to write the updated test first) but I think this is simpler and cleaner - Graphics2D g2 = (Graphics2D) g; + Graphics2D g2; + if (g instanceof Graphics2D) { + g2 = (Graphics2D)g; + } else { + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + g2 = image.createGraphics(); + } final AffineTransform savedAT = g2.getTransform(); if (!progressBar.getComponentOrientation().isLeftToRight()) { //Scale operation: Flips component about pivot @@ -200,7 +207,7 @@ protected void paint(final Graphics g) { g2.scale(-1, 1); g2.translate(-progressBar.getWidth(), 0); } - painter.paint(g, progressBar, i.left, i.top, width, height); + painter.paint(g2, progressBar, i.left, i.top, width, height); ------------- PR Comment: https://git.openjdk.org/jdk/pull/31749#issuecomment-5038515990
