[jdk20] RFR: 8301989: new javax.swing.text.DefaultCaret().setBlinkRate(N) results in NPE [v2]
Phil Race
prr at openjdk.org
Wed Feb 8 21:04:52 UTC 2023
On Wed, 8 Feb 2023 20:12:28 GMT, Phil Race <prr at openjdk.org> wrote:
>>> if we create a caret, then call setBlinkRate(), and then install()
>>> then the blink rate appears to be ignored whereas before 4512626 it was applied.
>>
>> Ok, if the text component is already visible and editable and focused and we install the new caret then the blink rate will not have an effect until the focus is lost and regained or until it became non-editable - and i think that was close to what we had before and there is a bug to investigate and optimize such corner case. In all other cases the code works fine. The value set is being preserved and will be reactivated when any of the methods such as focusGained or when the component installUI is called - if the cursor is set before component becomes visible - will cause to re-evaluate the blink rate and the stored value set by user will take place.
>
> Suppose I have this code
>
> Caret c = new DefaultCaret()
> c.setBlinkRate(50);
> c.install(editableJComponent);
>
> BEFORE 4512626 the JDK code looked like this
>
> if (rate != 0) {
> if (flasher == null) {
> flasher = new Timer(rate, handler);
> }
> flasher.setDelay(rate);
> }
>
>
> With your fix it looks like this
>
> if (rate != 0) {
> if (component != null && component.isEditable()) {
> if (flasher == null) {
> flasher = new Timer(rate, handler);
> }
> }
> }
>
>
> So with my sample application code there's a change that my blink rate is completely lost.
So it seems that in such a case, "savedBlinkRate" is still set and that is used to both report the value of blink rate *and* create & start a Timer when it is needed.
It is a little hard to follow through all those "when it is needed" cases but if we are attached to an enabled & editable component when focusGained() is called it should then start the flasher timer.
-------------
PR: https://git.openjdk.org/jdk20/pull/122
More information about the client-libs-dev
mailing list