On Tue, 21 Apr 2026 13:00:25 GMT, Alexey Ivanov <[email protected]> wrote:

>> Alexander Zuev has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Add null check for caret and background color reported by the component.
>
> src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java line 702:
> 
>> 700:                     int green = (caretColor.getGreen() + bg.getGreen()) 
>> / 2;
>> 701:                     int blue = (caretColor.getBlue() + bg.getBlue()) / 
>> 2;
>> 702:                     int alpha = 127;
> 
> Would it be enough to change the alpha component of the caret only?

That might be simpler.
It occurred that the code above could cause an IAE since the Color constructor 
requires values to be in range.
If the caret is white and the bg is say rgb(2, 2,2) then you'll pass 256 and 
get an exception.
It needs to be clamped.

There are also methods on java.awt.Color
Color.darker()
and
Color.brighter()

which could be used, but you'd first need to examine the caret color and 
probably the background too,  to know which one is appropriate.

ie for a light bg with a dark caret, you'll want to use brighter() to reduce 
the contrast.
And vice versa.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30758#discussion_r3120289119

Reply via email to