<Swing Dev> [10] RFR JDK-8187957:Tab Size does not work correctly in JTextArea

Semyon Sadetsky semyon.sadetsky at oracle.com
Wed Nov 8 19:38:27 UTC 2017


On 11/08/2017 11:28 AM, Sergey Bylokhov wrote:

> On 08/11/2017 10:39, Semyon Sadetsky wrote:
>> It also may be written as
>>
>>       int ntabs = (int)((x - tabBase) / tabSize);
>>       return tabBase + (ntabs + 1) * tabSize
>
> Yes "(int)+1" is also can be used for positive values, but the 
> "ceil()" is better since this purpose of this method, and in general 
> it works for negative values as well.
There may not be negative values here, so Math.ceil() is redundant.

--Semyon
>
>>
>>
>> On 11/08/2017 10:24 AM, Sergey Bylokhov wrote:
>>> Hi, Prasanta.
>>> Is it possible that dropping the float part of "tabSize" and "x" 
>>> will cause Off-by-one error? For example:
>>>     float tabSize=3.99f;
>>>     float x=21.9f;
>>>     int tabBase=0;
>>>  649         int ntabs = ((int) x - tabBase) / (int)tabSize;
>>>  650         return tabBase + ((ntabs + 1) * tabSize);
>>>
>>> The result is: ntabs=7 -> 31.92 which is not correct.
>>>
>>> I guess you will need something like this:
>>>     int ntabs = (int) Math.ceil((x - tabBase) / tabSize);
>>>     return tabBase + ntabs * tabSize;
>>> The result is: ntabs=6 -> 23.94
>>>
>>>
>>> On 08/11/2017 03:25, Prasanta Sadhukhan wrote:
>>>> Hi All,
>>>>
>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8187957
>>>> webrev: http://cr.openjdk.java.net/~psadhukhan/8187957/webrev.00/
>>>>
>>>> Please review a fix for an issue where it is seen string with "tab" 
>>>> in them are not aligned properly.
>>>> This is because while calculating tab stop postion, it is 
>>>> calculating number of tabs in float value (an aftereffect of 
>>>> JDK-8156217 <https://bugs.openjdk.java.net/browse/JDK-8156217>)
>>>> so next tab stop location is coming out wrong.
>>>> Fix is to use "number of tabs" as an integer value in order to 
>>>> calculate the tab position correctly.
>>>>
>>>> Regards
>>>> Prasanta
>>>
>>>
>>
>
>




More information about the swing-dev mailing list