Closed jzwolak closed 2 years ago
It is actually a bug (regression in FlatLaf 2.0) that all text is selected in JTextArea
, JTextPane
and JEditorPane
when component is focused for the first time.
Only JTextField
and subclasses should select all text when focused.
This is how native text fields in various operating systems usually behave.
Select all text in multi-line text components usually makes no sense IMHO.
The regression is caused by PR #401 (commit 0156a9a9d51349ce606bceccc3380fcb1e27b814), which added FlatCaret
usage to JTextArea
, JTextPane
and JEditorPane
. Before this PR, FlatCaret
was only used for JTextField
and subclasses.
Fixed in FlatLaf 2.1
In
FlatTextAreaUI.createCaret()
the call is madenew FlatCaret( null, false );
setting theselectAllOnFocusPolicy
to the default. Yet inFlatTextFieldUI.createCaret()
the call readsnew FlatCaret( "TextComponent.selectAllOnFocusPolicy"), UIManager.getBoolean( "TextComponent.selectAllOnMouseClick" ) );
. I think the two calls should be the same; in fact, maybe the two classes should be inheriting a common base class that implementscreateCaret
(and other common methods on text components).As it stands,
JTextArea
will always select the text on first focus gained because that is the default behavior and there is no way to change this.JTextField
is configurable with theTextComponent.selectAllOnFocusPolicy
. I think the policy should apply toJTextArea
, too. If not, then a similar configuration options forJTextArea
is warranted.I have a hard time imagining developers wanting to change the policy on
JTextField
but notJTextArea
, so I believe this constitutes a bug and can safely be changed. If differing configurability between the two is desired, then having a separate option seems acceptable. Though I recognize it's more difficult to add a separate option than to use the existing one. Having a separate option also adds complexity to the usability of the code.