RFR: 7175396: The text on label is not painted red for Nimbus LaF. [v3]
Alexey Ivanov
aivanov at openjdk.org
Tue Sep 27 17:49:22 UTC 2022
On Tue, 13 Sep 2022 07:49:38 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> Label.foreground UIProperty is not honored by Nimbus L&F.
>> Added support for setting JLabel foreground color for Nimbus L&F
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Get color once during init
src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLabelUI.java line 222:
> 220: if (fgColor != null) {
> 221: label.setForeground(fgColor);
> 222: }
Why is the color set to the `label` component during paint?
Shouldn't it be `g.setColor(fgColor)`? And the above code which uses the `context` should be skipped if `fgColor != null`.
test/jdk/javax/swing/plaf/nimbus/TestNimbusLabel.java line 48:
> 46: private static JLabel label;
> 47: private static JFrame frame;
> 48: private static boolean passed = false;
`passed` could be local variable in `main`.
`label` could also be local variable inside the lambda expression which creates the UI.
test/jdk/javax/swing/plaf/nimbus/TestNimbusLabel.java line 75:
> 73: frame = new JFrame();
> 74: UIManager.getDefaults().put("Label.foreground",
> 75: java.awt.Color.red);
You import `Color` class, there's no need to specify the full class name. You should use `RED` as constants are in upper case.
test/jdk/javax/swing/plaf/nimbus/TestNimbusLabel.java line 97:
> 95: System.out.println("color(" + x + "," + y + ")=" +
> 96: robot.getPixelColor(x, y));
> 97: Color color = robot.getPixelColor(x, y);
Suggestion:
Color color = robot.getPixelColor(x, y);
System.out.println("color(" + x + "," + y + ")=" +
color);
test/jdk/javax/swing/plaf/nimbus/TestNimbusLabel.java line 98:
> 96: robot.getPixelColor(x, y));
> 97: Color color = robot.getPixelColor(x, y);
> 98: if (checkPixel(color)) {
I wonder if disabling text antialiasing would yield a simpler code in `checkPixel`? However, it cannot be disabled on macOS which still uses grayscale antialiasing. But for Windows and Linux, it should help. Or the test could be limited to Windows and Linux.
-------------
PR: https://git.openjdk.org/jdk/pull/9900
More information about the client-libs-dev
mailing list