From a1395a5490dc44862f8d3f142f89b7577dc90764 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 6 Jan 2022 15:17:20 +0100 Subject: [PATCH] TextField: leading/trailing components (PR #386): - set cursor only on button and toolbar - do not replace cursor on if already set (issue #461) - updated client properties javadoc --- .../formdev/flatlaf/FlatClientProperties.java | 31 +++++++++++++------ .../formdev/flatlaf/ui/FlatTextFieldUI.java | 11 +++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index 4f398439..0fb5e513 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -874,7 +874,26 @@ public interface FlatClientProperties * The component should be not opaque because the text field border is painted * slightly inside the usually visible border in some cases. * E.g. when focused (in some themes) or when an outline color is specified - * (see {@link #OUTLINE}. + * (see {@link #OUTLINE}). + *

+ * The component is prepared in the following way: + *

+ * Because text fields use the text cursor by default and the cursor is inherited by child components, + * it may be necessary to explicitly set component cursor if you e.g. need the default arrow cursor. + * E.g. {@code comp.setCursor( Cursor.getDefaultCursor() )}. + *

+ * Styling is used to modify insets/margins and appearance of buttons and toolbars + * so that they fit nicely into the text field and do not increase text field height. + * See styles {@code [style]Button.inTextField} and {@code [style]ToolBar.inTextField} + * in {@code Flat[Light|Dark]Laf.properties}. *

* Component {@link javax.swing.JTextField} (and subclasses)
* Value type {@link javax.swing.JComponent} @@ -886,15 +905,7 @@ public interface FlatClientProperties /** * Specifies a component that will be placed at the trailing edge of the text field. *

- * The component will be positioned inside and aligned to the visible text field border. - * There is no gap between the visible border and the component. - * The laid out component size will be the preferred component width - * and the inner text field height. - *

- * The component should be not opaque because the text field border is painted - * slightly inside the usually visible border in some cases. - * E.g. when focused (in some themes) or when an outline color is specified - * (see {@link #OUTLINE}. + * See {@link #TEXT_FIELD_LEADING_COMPONENT} for details. *

* Component {@link javax.swing.JTextField} (and subclasses)
* Value type {@link javax.swing.JComponent} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index 66c7056d..65876191 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -826,15 +826,20 @@ debug*/ /** @since 2 */ protected void prepareLeadingOrTrailingComponent( JComponent c ) { c.putClientProperty( STYLE_CLASS, "inTextField" ); - c.setCursor( Cursor.getDefaultCursor() ); - if( c instanceof JButton || c instanceof JToggleButton ) + if( c instanceof JButton || c instanceof JToggleButton ) { c.putClientProperty( BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON ); - else if( c instanceof JToolBar ) { + + if( !c.isCursorSet() ) + c.setCursor( Cursor.getDefaultCursor() ); + } else if( c instanceof JToolBar ) { for( Component child : c.getComponents() ) { if( child instanceof JComponent ) ((JComponent)child).putClientProperty( STYLE_CLASS, "inTextField" ); } + + if( !c.isCursorSet() ) + c.setCursor( Cursor.getDefaultCursor() ); } }