RFR: 7175396: The text on label is not painted red for Nimbus LaF. [v3]

Alexey Ivanov aivanov at openjdk.org
Thu Sep 29 12:22:15 UTC 2022


On Wed, 28 Sep 2022 06:42:07 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> 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`.
>
> There are 2 ways JLabel can be used, one via html label and another normal label. Normal label text will work if we do `g.setColor(fgColor)` but html label will use [StyleSheet.paint](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java#L1939) which does not take into account foreground Color (guess unless it's provided by html tags which is not the case here) so I need to explicitly set the foreground color of label

Do other L&Fs respect the `Label.foreground` color if the label text contains HTML?

Why is it set in each paint then? It should be set once in `installDefaults` and it should be removed in `uninstallDefaults`. In addition to that, it is to be installed if and only if `label.setForeground` is `null` or `instanceof UIResource`, and uninstalled if it is `instanceof UIResource`. If the user explicitly set foreground color of the label, it must not be overridden by the L&Fs.

-------------

PR: https://git.openjdk.org/jdk/pull/9900



More information about the client-libs-dev mailing list