RFR: 8178368: Right and Center alignment of text field works incorrectly [v4]

Karthik P K kpk at openjdk.org
Fri Feb 10 13:51:59 UTC 2023


On Fri, 10 Feb 2023 05:39:33 GMT, Karthik P K <kpk at openjdk.org> wrote:

>> When Text width was more than TextField width, the logic to update `textTranslateX` in `updateCaretOff` method was causing the issue of unexpected behavior for Right and Center alignment.
>> 
>> Made changes to update `textTranslateX` in `updateCaretOff` method only when text width is less than text field width i.e `delta` is positive. 
>> For both right and center alignments, the `textTranslateX` value calculated in `updateTextPos` method will be updated without any condition so that expected behavior is achieved for all scenarios of text width relative to text field width. 
>> 
>> Added unit tests to validate LEFT, CENTER and RIGHT alignments. RIGHT and CENTER alignment tests are expected to fail without the fix provided in this PR.
>
> Karthik P K has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
> 
>  - Merge branch 'openjdk:master' into textfield_issue_fix
>  - Update comments
>  - Fix textfield right and center alignment issues
>  - Fix for TextField right alignement issue

I checked with HTML textfield and swing JTextField. In both the cases, the text gets aligned to the left (beginning of the text is shown) regardless of alignment type when text length is more than text field length.
In html textfield, even prompt text has same behavior but in JavaFX prompt text gets aligned to the center (center of the text is displayed) or right (beginning of the text is hidden) as specified even when the prompt text length is more than textfield length.

The case where prompt text length is more than text field length might not be frequent but I think we should have same behavior for both. So I think we should fix either the behavior of the text or the  prompt text so that both are consistent.

I went ahead with the option of fixing the behavior of text because aligning the text according to the set value regardless of the text length looked like predictable behavior.
Let me know your thoughts on this.

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

PR: https://git.openjdk.org/jfx/pull/980


More information about the openjfx-dev mailing list