Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8298083: The "CheckBox/RadioButton[Enabled/Disabled].textForeground" …
…stoped working

Reviewed-by: psadhukhan
  • Loading branch information
mrserb committed Dec 8, 2022
1 parent c16eb89 commit 5540a8c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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
Expand Down Expand Up @@ -286,18 +286,6 @@ else if (type == ColorType.TEXT_FOREGROUND) {
}
}
}

if ((c instanceof JCheckBox) && (state & SynthConstants.DISABLED) != 0) {
if (UIManager.getColor("CheckBox.disabledText") != null) {
return UIManager.getColor("CheckBox.disabledText");
}
} else if ((c instanceof JRadioButton) &&
(state & SynthConstants.DISABLED) != 0) {
if (UIManager.getColor("RadioButton.disabledText") != null) {
return UIManager.getColor("RadioButton.disabledText");
}
}

return getColorForState(context, type);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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
Expand Down Expand Up @@ -779,14 +779,6 @@ public Color getColor(SynthContext context, ColorType type) {
(type == ColorType.FOREGROUND ||
type == ColorType.TEXT_FOREGROUND)) {
return getColorForState(context, type);
} else if (c instanceof JCheckBox) {
if (UIManager.getColor("CheckBox.disabledText") != null) {
return UIManager.getColor("CheckBox.disabledText");
}
} else if (c instanceof JRadioButton) {
if (UIManager.getColor("RadioButton.disabledText") != null) {
return UIManager.getColor("RadioButton.disabledText");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/jdk/ProblemList.txt
Expand Up @@ -664,6 +664,7 @@ 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
java/awt/Window/8159168/SetShapeTest.java 8274106 macosx-aarch64
Expand Down
40 changes: 28 additions & 12 deletions test/jdk/javax/swing/JRadioButton/4314194/bug4314194.java
Expand Up @@ -23,7 +23,7 @@
/*
* @test
* @key headful
* @bug 4314194 8075916
* @bug 4314194 8075916 8298083
* @summary Verifies disabled color for JCheckbox and JRadiobutton is honored in all L&F
* @run main bug4314194
*/
Expand All @@ -40,13 +40,14 @@
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.synth.SynthLookAndFeel;

public class bug4314194 {
private static JFrame frame;
private static JRadioButton radioButton;
private static JCheckBox checkBox;
private static Point point;
private static Rectangle rect;
private static volatile JFrame frame;
private static volatile JRadioButton radioButton;
private static volatile JCheckBox checkBox;
private static volatile Point point;
private static volatile Rectangle rect;
private static Robot robot;
private static final Color radioButtonColor = Color.RED;
private static final Color checkboxColor = Color.GREEN;
Expand Down Expand Up @@ -87,9 +88,25 @@ private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
}
}

private static void createUI() {
UIManager.getDefaults().put("CheckBox.disabledText", checkboxColor);
UIManager.getDefaults().put("RadioButton.disabledText", radioButtonColor);
private static void createUI(String laf) {
if (UIManager.getLookAndFeel() instanceof SynthLookAndFeel) {
// reset "basic" properties
UIManager.getDefaults().put("CheckBox.disabledText", null);
UIManager.getDefaults().put("RadioButton.disabledText", null);
// set "synth" properties
UIManager.getDefaults().put("CheckBox[Disabled].textForeground", checkboxColor);
// for some reason the RadioButton[Disabled] does not work
// see https://bugs.openjdk.org/browse/JDK-8298149
//UIManager.getDefaults().put("RadioButton[Disabled].textForeground", radioButtonColor);
UIManager.getDefaults().put("RadioButton[Enabled].textForeground", radioButtonColor);
} else {
// reset "synth" properties
UIManager.getDefaults().put("CheckBox[Disabled].textForeground", null);
UIManager.getDefaults().put("RadioButton[Enabled].textForeground", null);
// set "basic" properties
UIManager.getDefaults().put("CheckBox.disabledText", checkboxColor);
UIManager.getDefaults().put("RadioButton.disabledText", radioButtonColor);
}

checkBox = new JCheckBox("\u2588".repeat(5));
radioButton = new JRadioButton("\u2588".repeat(5));
Expand All @@ -98,7 +115,7 @@ private static void createUI() {
checkBox.setEnabled(false);
radioButton.setEnabled(false);

frame = new JFrame("bug4314194");
frame = new JFrame(laf);
frame.getContentPane().add(radioButton, BorderLayout.SOUTH);
frame.getContentPane().add(checkBox, BorderLayout.NORTH);
frame.pack();
Expand All @@ -122,7 +139,7 @@ public static void main(String[] args) throws Exception {
System.out.println("Testing L&F: " + laf.getClassName());
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
try {
SwingUtilities.invokeAndWait(() -> createUI());
SwingUtilities.invokeAndWait(() -> createUI(laf.getName()));
robot.waitForIdle();
robot.delay(1000);

Expand All @@ -141,4 +158,3 @@ public static void main(String[] args) throws Exception {
}
}
}

3 comments on commit 5540a8c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb
Copy link
Member Author

@mrserb mrserb commented on 5540a8c Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk20

@openjdk
Copy link

@openjdk openjdk bot commented on 5540a8c Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb the backport was successfully created on the branch mrserb-backport-5540a8c5 in my personal fork of openjdk/jdk20. To create a pull request with this backport targeting openjdk/jdk20:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5540a8c5 from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 8 Dec 2022 and was reviewed by Prasanta Sadhukhan.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk20:

$ git fetch https://github.com/openjdk-bots/jdk20 mrserb-backport-5540a8c5:mrserb-backport-5540a8c5
$ git checkout mrserb-backport-5540a8c5
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk20 mrserb-backport-5540a8c5

Please sign in to comment.