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
This commit is contained in:
Abhishek Kumar 2024-05-21 05:31:44 +00:00
parent 6e805127f8
commit fb45bab8e1
3 changed files with 125 additions and 2 deletions

View File

@ -669,7 +669,6 @@ javax/swing/JFileChooser/6798062/bug6798062.java 8146446 windows-all
javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
javax/swing/JRadioButton/4314194/bug4314194.java 8298153 linux-all
# Several tests which fail on some hidpi systems/macosx12-aarch64 system
javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -135,6 +135,10 @@ public class bug4314194 {
if (laf.getClassName().contains("Motif")) {
System.out.println("Skipping Motif L&F as it is deprecated");
continue;
} else if (laf.getClassName().contains("GTK")) {
System.out.println("GTK doesn't support color setting explicitly" +
" specified by user using UIManager property.");
continue;
}
System.out.println("Testing L&F: " + laf.getClassName());
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));

View File

@ -0,0 +1,120 @@
/*
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.File;
import java.io.IOException;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
/*
* @test
* @bug 4248210
* @key headful
* @summary Tests that HTML in JLabel is painted using LAF-defined
foreground color
* @run main bug4248210
*/
public class bug4248210 {
private static final Color labelColor = Color.red;
public static void main(String[] args) throws Exception {
for (UIManager.LookAndFeelInfo laf :
UIManager.getInstalledLookAndFeels()) {
if (!(laf.getName().contains("Motif") || laf.getName().contains("GTK"))) {
System.out.println("Testing LAF: " + laf.getName());
SwingUtilities.invokeAndWait(() -> test(laf));
}
}
}
private static void test(UIManager.LookAndFeelInfo laf) {
setLookAndFeel(laf);
if (UIManager.getLookAndFeel() instanceof NimbusLookAndFeel) {
// reset "basic" properties
UIManager.getDefaults().put("Label.foreground", null);
// set "synth - nimbus" properties
UIManager.getDefaults().put("Label[Enabled].textForeground", labelColor);
} else {
// reset "synth - nimbus" properties
UIManager.getDefaults().put("Label[Enabled].textForeground", null);
// set "basic" properties
UIManager.getDefaults().put("Label.foreground", labelColor);
}
JLabel label = new JLabel("<html><body>Can You Read This?</body></html>");
label.setSize(150, 30);
BufferedImage img = paintToImage(label);
if (!chkImgForegroundColor(img)) {
try {
ImageIO.write(img, "png", new File("Label_" + laf.getName() + ".png"));
} catch (IOException ignored) {}
throw new RuntimeException("JLabel not painted with LAF defined " +
"foreground color");
}
System.out.println("Test Passed");
}
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
try {
UIManager.setLookAndFeel(laf.getClassName());
} catch (UnsupportedLookAndFeelException ignored) {
System.out.println("Unsupported LAF: " + laf.getClassName());
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static BufferedImage paintToImage(JComponent content) {
BufferedImage im = new BufferedImage(content.getWidth(), content.getHeight(),
TYPE_INT_RGB);
Graphics2D g = (Graphics2D) im.getGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, content.getWidth(), content.getHeight());
content.paint(g);
g.dispose();
return im;
}
private static boolean chkImgForegroundColor(BufferedImage img) {
for (int x = 0; x < img.getWidth(); ++x) {
for (int y = 0; y < img.getHeight(); ++y) {
if (img.getRGB(x, y) == labelColor.getRGB()) {
return true;
}
}
}
return false;
}
}