RFR: 8335547: Support multi-line prompt text for TextArea

Michael Strauß mstrauss at openjdk.org
Fri Mar 21 06:03:28 UTC 2025


On Sun, 16 Mar 2025 09:10:22 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:

>> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java line 739:
>> 
>>> 737:             s = s.replace("\n", "");
>>> 738:             return s;
>>> 739:         }, getSkinnable().promptTextProperty()));
>> 
>> two minor problems:
>> 1. missing { } after `if`.  (I would highly recommend always using { })
>> 2. when s is null you call replace() unnecessarily
>> 
>> suggestion:
>> 
>>             String s = getSkinnable().getPromptText();
>>             if (s == null) {
>>                 return "";
>>             }
>>             return s.replace("\n", "");
>
> You should consider using a fluent binding here, which is a more modern solution compared to the `Bindings` class. It is also simpler because you don't need to check for `null`:
> 
> 
> promptNode.textProperty().bind(getSkinnable().promptTextProperty().map(s -> s.replace("\n", "")));

Have you considered the suggestion?

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1716#discussion_r2006899928


More information about the openjfx-dev mailing list