On Tue, 21 Apr 2026 21:14:04 GMT, Alexander Zuev <[email protected]> wrote:

>> 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.
>
>> If the caret is white and the bg is say rgb(2, 2,2) then you'll pass 256
> 
> No, i will not. The white is rgb(255, 255, 255) and bg is rgb(2, 2, 2) then i 
> will pass rgb ((2 + 255) / 2, (2 + 255) / 2, (2 + 255) /2) which is rgb(128, 
> 128, 128) which is gray - perfectly fits the purpose of the fix.

> Would it be enough to change the alpha component of the caret only?

Not sure it will work good on all color combinations so i did both added alpha 
value of 50% and brought color half way to the background.

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

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

Reply via email to