Skip to content

Commit fb45bab

Browse files
author
Abhishek Kumar
committed
8075917: The regression-swing case failed as the text on label is not painted red with the GTK L&F
8298153: Colored text is not shown on disabled checkbox and radio button with GTK LAF for bug4314194 Reviewed-by: tr, psadhukhan
1 parent 6e80512 commit fb45bab

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ javax/swing/JFileChooser/6798062/bug6798062.java 8146446 windows-all
669669
javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all
670670
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
671671
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
672-
javax/swing/JRadioButton/4314194/bug4314194.java 8298153 linux-all
673672

674673
# Several tests which fail on some hidpi systems/macosx12-aarch64 system
675674
javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64

test/jdk/javax/swing/JRadioButton/4314194/bug4314194.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2024, 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
@@ -135,6 +135,10 @@ public static void main(String[] args) throws Exception {
135135
if (laf.getClassName().contains("Motif")) {
136136
System.out.println("Skipping Motif L&F as it is deprecated");
137137
continue;
138+
} else if (laf.getClassName().contains("GTK")) {
139+
System.out.println("GTK doesn't support color setting explicitly" +
140+
" specified by user using UIManager property.");
141+
continue;
138142
}
139143
System.out.println("Testing L&F: " + laf.getClassName());
140144
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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+
import java.io.File;
25+
import java.io.IOException;
26+
import java.awt.Color;
27+
import java.awt.Graphics2D;
28+
import java.awt.image.BufferedImage;
29+
import javax.imageio.ImageIO;
30+
import javax.swing.JComponent;
31+
import javax.swing.JLabel;
32+
import javax.swing.SwingUtilities;
33+
import javax.swing.UIManager;
34+
import javax.swing.UnsupportedLookAndFeelException;
35+
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
36+
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
37+
38+
/*
39+
* @test
40+
* @bug 4248210
41+
* @key headful
42+
* @summary Tests that HTML in JLabel is painted using LAF-defined
43+
foreground color
44+
* @run main bug4248210
45+
*/
46+
47+
public class bug4248210 {
48+
private static final Color labelColor = Color.red;
49+
50+
public static void main(String[] args) throws Exception {
51+
for (UIManager.LookAndFeelInfo laf :
52+
UIManager.getInstalledLookAndFeels()) {
53+
if (!(laf.getName().contains("Motif") || laf.getName().contains("GTK"))) {
54+
System.out.println("Testing LAF: " + laf.getName());
55+
SwingUtilities.invokeAndWait(() -> test(laf));
56+
}
57+
}
58+
}
59+
60+
private static void test(UIManager.LookAndFeelInfo laf) {
61+
setLookAndFeel(laf);
62+
if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel) {
63+
// reset "basic" properties
64+
UIManager.getDefaults().put("Label.foreground", null);
65+
// set "synth - nimbus" properties
66+
UIManager.getDefaults().put("Label[Enabled].textForeground", labelColor);
67+
} else {
68+
// reset "synth - nimbus" properties
69+
UIManager.getDefaults().put("Label[Enabled].textForeground", null);
70+
// set "basic" properties
71+
UIManager.getDefaults().put("Label.foreground", labelColor);
72+
}
73+
74+
JLabel label = new JLabel("<html><body>Can You Read This?</body></html>");
75+
label.setSize(150, 30);
76+
77+
BufferedImage img = paintToImage(label);
78+
if (!chkImgForegroundColor(img)) {
79+
try {
80+
ImageIO.write(img, "png", new File("Label_" + laf.getName() + ".png"));
81+
} catch (IOException ignored) {}
82+
throw new RuntimeException("JLabel not painted with LAF defined " +
83+
"foreground color");
84+
}
85+
System.out.println("Test Passed");
86+
}
87+
88+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
89+
try {
90+
UIManager.setLookAndFeel(laf.getClassName());
91+
} catch (UnsupportedLookAndFeelException ignored) {
92+
System.out.println("Unsupported LAF: " + laf.getClassName());
93+
} catch (ClassNotFoundException | InstantiationException
94+
| IllegalAccessException e) {
95+
throw new RuntimeException(e);
96+
}
97+
}
98+
99+
private static BufferedImage paintToImage(JComponent content) {
100+
BufferedImage im = new BufferedImage(content.getWidth(), content.getHeight(),
101+
TYPE_INT_RGB);
102+
Graphics2D g = (Graphics2D) im.getGraphics();
103+
g.setBackground(Color.WHITE);
104+
g.clearRect(0, 0, content.getWidth(), content.getHeight());
105+
content.paint(g);
106+
g.dispose();
107+
return im;
108+
}
109+
110+
private static boolean chkImgForegroundColor(BufferedImage img) {
111+
for (int x = 0; x < img.getWidth(); ++x) {
112+
for (int y = 0; y < img.getHeight(); ++y) {
113+
if (img.getRGB(x, y) == labelColor.getRGB()) {
114+
return true;
115+
}
116+
}
117+
}
118+
return false;
119+
}
120+
}

0 commit comments

Comments
 (0)