Skip to content

Commit fe5911c

Browse files
committed
8373946: Synth ProgressBarUI implementation confuses background painting with border painting
Reviewed-by: prr, kizune, azvegint
1 parent 2d09284 commit fe5911c

File tree

3 files changed

+127
-114
lines changed

3 files changed

+127
-114
lines changed

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthProgressBarUI.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -216,11 +216,9 @@ public void update(Graphics g, JComponent c) {
216216

217217
SynthLookAndFeel.update(context, g);
218218

219-
if (((JProgressBar) c).isBorderPainted()) {
220-
context.getPainter().paintProgressBarBackground(context,
221-
g, 0, 0, c.getWidth(), c.getHeight(),
222-
progressBar.getOrientation());
223-
}
219+
context.getPainter().paintProgressBarBackground(context,
220+
g, 0, 0, c.getWidth(), c.getHeight(),
221+
progressBar.getOrientation());
224222
paint(context, g);
225223
}
226224

test/jdk/javax/swing/JProgressBar/TestProgressBarBorder.java

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8192888
27+
* @key headful
28+
* @summary Verifies ProgressBar in Synth L&F renders background
29+
* when border is not painted
30+
* @run main TestNimbusProgressBarBorder
31+
*/
32+
33+
import java.io.File;
34+
35+
import java.awt.BorderLayout;
36+
import java.awt.Color;
37+
import java.awt.Graphics2D;
38+
import java.awt.GridBagLayout;
39+
import java.awt.image.BufferedImage;
40+
import java.awt.Rectangle;
41+
import java.awt.Robot;
42+
43+
import javax.imageio.ImageIO;
44+
45+
import javax.swing.JFrame;
46+
import javax.swing.JPanel;
47+
import javax.swing.JProgressBar;
48+
import javax.swing.UIManager;
49+
import javax.swing.SwingUtilities;
50+
51+
public class TestNimbusProgressBarBorder {
52+
53+
private static JFrame frame;
54+
private static JProgressBar progressBar;
55+
private static boolean failure = true;
56+
private static volatile Rectangle rect;
57+
58+
public static void main(String[] args) throws Exception {
59+
int width = 200;
60+
int height = 100;
61+
try {
62+
Robot robot = new Robot();
63+
SwingUtilities.invokeAndWait(() -> {
64+
try {
65+
// Set Nimbus L&F
66+
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
67+
} catch (Exception e) {
68+
throw new RuntimeException(e);
69+
}
70+
frame = new JFrame("Nimbus JProgressBar Test");
71+
frame.setSize(width, height);
72+
73+
// ProgressBar setup
74+
progressBar = new JProgressBar(0, 100);
75+
progressBar.setValue(0);
76+
progressBar.setBorderPainted(false);
77+
78+
JPanel center = new JPanel(new GridBagLayout());
79+
center.setBackground(Color.WHITE);
80+
center.add(progressBar);
81+
82+
frame.add(center, BorderLayout.CENTER);
83+
frame.setLocationRelativeTo(null);
84+
frame.setVisible(true);
85+
});
86+
robot.waitForIdle();
87+
robot.delay(1000);
88+
SwingUtilities.invokeAndWait(() -> {
89+
rect = progressBar.getBounds();
90+
});
91+
92+
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
93+
Graphics2D g2d = (Graphics2D) img.getGraphics();
94+
g2d.setColor(Color.WHITE);
95+
g2d.fillRect(0, 0, rect.width, rect.height);
96+
progressBar.paint(g2d);
97+
g2d.dispose();
98+
99+
robot.waitForIdle();
100+
robot.delay(100);
101+
102+
for (int x = 10; x < (10 + rect.width / 2); x++) {
103+
for (int y = 10; y < (10 + rect.height / 2); y++) {
104+
Color col = new Color(img.getRGB(x, y));
105+
if (!col.equals(Color.WHITE)) {
106+
failure = false;
107+
break;
108+
}
109+
}
110+
}
111+
if (failure) {
112+
ImageIO.write(img, "png", new File("ProgressBarTest.png"));
113+
throw new RuntimeException("ProgressBar background not drawn");
114+
}
115+
} finally {
116+
SwingUtilities.invokeAndWait(() -> {
117+
if (frame != null) {
118+
frame.dispose();
119+
}
120+
});
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)