<Swing Dev> [11] RFR: JDK-8199441: Wrong caret position in multiline text components on Windows with a screen resolution higher than 100%

Phil Race philip.race at oracle.com
Tue Jun 5 18:17:47 UTC 2018

My explanation for my thinking is already written in the email you are 
replying to ..


On 05/31/2018 11:07 PM, Prasanta Sadhukhan wrote:
> Hi Phil,
> Any feedback as to why you find this is not the right fix? I could not 
> find anything in JDK-8168992 to guess it is not.
> As told, there was no regression with jck and jtreg tests with the fix.
> Regards
> Prasanta
> On 5/9/2018 12:41 AM, Phil Race wrote:
>> I am not sure this is the right fix.
>> If the intention had been to change all calls to 
>> getTabbedTextOffset() to use the FP
>> API it would have just been changed .. rather than adding a new API 
>> that provides
>> the option to specify whether to use FP.
>> So perhaps the problem is that internal code needs to be updated to 
>> call the FP
>> version directly ..
>> I'd like to read https://bugs.openjdk.java.net/browse/JDK-8168992 to see
>> what was said there but JBS just went down for 5 hours maintenance ..
>> -phil.
>> On 05/07/2018 11:54 PM, Prasanta Sadhukhan wrote:
>>> Hi Sergey,
>>> I have run javax/swing/text jtreg and jck tests and did not observe 
>>> any regressions.
>>> Regards
>>> Prasanta
>>> On 4/28/2018 5:38 AM, Sergey Bylokhov wrote:
>>>> Hi, Prasanta.
>>>> Please confirm that you run related jck/reg tests.
>>>> On 26/04/2018 23:52, Prasanta Sadhukhan wrote:
>>>>> Hi All,
>>>>> Please review a fix for an issue where it is seen that,
>>>>>   with a screen resolution higher than 100% and then clicking in a 
>>>>> JTextArea having setLineWrap(true) set, the caret (insertion 
>>>>> point) is not aligned with the cursor.
>>>>> The issue seems to stem from the fact that caret position 
>>>>> calculation in DefaultCaret class utilises API that uses integer 
>>>>> calculation than floating point calculations.
>>>>> The code flow as seen is
>>>>> DefaultCaret#positionCaret=>BasicTextUI#viewToModel=>BoxView.viewToModel=>CompositeView#viewToModel=>WrappedPlainView#viewToModel=>Utilities.getTabbedOffset 
>>>>> Now, getTabbedOffset utilises FontMetrics.charsWidth() which uses 
>>>>> integer arithmetic to get the caret position.
>>>>> The same getTabbedOffset uses Font.getStringBounds() which uses 
>>>>> floating point arithmetic via Rectangle2D.Float.
>>>>> Proposed fix is to make sure getTabbedOffset uses floating point 
>>>>> calculations by using getStringBounds() instead of charsWidth() so 
>>>>> that it calculates
>>>>> the character width(s) of text present in JTextArea in floating 
>>>>> point to align the caret.
>>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8199441
>>>>> webrev: http://cr.openjdk.java.net/~psadhukhan/8199441/webrev.00/
>>>>> Regards
>>>>> Prasanta

More information about the swing-dev mailing list