RichTextArea: RichTextArea doesn't have a setText method, but CodeArea does
Andy Goryachev
andy.goryachev at oracle.com
Thu May 1 17:49:34 UTC 2025
This API is designed specifically not to confuse - there is no "text" property in RichTextArea, cannot be. There is the "model" property, and the corresponding setModel(). It is different with the CodeArea because the CodeModel does operate with (decorated) plain text.
Additionally, the end result of clear/appendText/replaceText/insertText might depend on the existing paragraph attributes.
It's the same reason we don't have setText() in the TextFlow.
-andy
From: openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of PavelTurk <pavelturk2000 at gmail.com>
Date: Thursday, May 1, 2025 at 10:41
To: openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
Subject: Re: RichTextArea: RichTextArea doesn't have a setText method, but CodeArea does
To be honest, I think this will create problems when working with the RichTextArea API.
Why? Because every developer will intuitively look for setText. For example, TextArea
—https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextArea.html —
has setText. CodeArea has setText. But RichTextArea doesn't.
This doesn't seem very good. But that's just my personal opinion.
Best regards, Pavel
On 5/1/25 20:32, Kevin Rushforth wrote:
Note that there is an easy way to set plain text if you are using a writable model:
rta.clear();
rta.appendText(String text);
-- Kevin
On 5/1/2025 7:55 AM, Andy Goryachev wrote:
Intentionally: the CodeArea model contains plain text, while in the RichTextArea the content depends on the model. It may not contain anything and be generated on the fly.
-andy
From: openjfx-dev <openjfx-dev-retn at openjdk.org><mailto:openjfx-dev-retn at openjdk.org> on behalf of PavelTurk <pavelturk2000 at gmail.com><mailto:pavelturk2000 at gmail.com>
Date: Thursday, May 1, 2025 at 05:40
To: openjfx-dev at openjdk.org<mailto:openjfx-dev at openjdk.org> <openjfx-dev at openjdk.org><mailto:openjfx-dev at openjdk.org>
Subject: RichTextArea: RichTextArea doesn't have a setText method, but CodeArea does
I've just found out that RichTextArea doesn't have a setText method, but CodeArea does.
Is this a mistake or was it done intentionally?
Best regards, Pavel
PS. Just don't think I spend my free time analyzing Javadoc. It's just that I once opened an issue in RTFX suggesting
to add a setText method, and today, seeing this issue, I decided to mention that JavaFX RichTextArea has such
a method. However, I was surprised not to find it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250501/49102438/attachment-0001.htm>
More information about the openjfx-dev
mailing list