diff --git a/CHANGELOG.md b/CHANGELOG.md index afd4dd72..f4e29868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ FlatLaf Change Log combo box and vertical scroll bar is visible. (issue #137) - MenuItem on macOS: Removed plus characters from accelerator text and made modifier key order conform with macOS standard. (issue #141) +- FileChooser: Fixed too small text field when renaming a file/directory in Flat + IntelliJ/Darcula themes. (issue #143) ## 0.38 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java index bfad3254..cf75aed8 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java @@ -87,7 +87,7 @@ public class FlatBorder try { FlatUIUtils.setRenderingHints( g2 ); - boolean isCellEditor = isTableCellEditor( c ); + boolean isCellEditor = isCellEditor( c ); float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) ); float borderWidth = scale( (float) getBorderWidth( c ) ); float arc = isCellEditor ? 0 : scale( (float) getArc( c ) ); @@ -95,7 +95,7 @@ public class FlatBorder // paint outer border if( outlineColor != null || isFocused( c ) ) { - float innerWidth = !(c instanceof JScrollPane) + float innerWidth = !isCellEditor && !(c instanceof JScrollPane) ? (outlineColor != null ? innerOutlineWidth : innerFocusWidth) : 0; @@ -198,13 +198,13 @@ public class FlatBorder return FlatUIUtils.isPermanentFocusOwner( c ); } - protected boolean isTableCellEditor( Component c ) { - return FlatUIUtils.isTableCellEditor( c ); + protected boolean isCellEditor( Component c ) { + return FlatUIUtils.isCellEditor( c ); } @Override public Insets getBorderInsets( Component c, Insets insets ) { - boolean isCellEditor = isTableCellEditor( c ); + boolean isCellEditor = isCellEditor( c ); float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) ); float ow = focusWidth + scale( (float) getLineWidth( c ) ); @@ -213,6 +213,18 @@ public class FlatBorder insets.left = Math.round( scale( (float) insets.left ) + ow ); insets.bottom = Math.round( scale( (float) insets.bottom ) + ow ); insets.right = Math.round( scale( (float) insets.right ) + ow ); + + if( isCellEditor ) { + // remove top and bottom insets if used as cell editor + insets.top = insets.bottom = 0; + + // remove right/left insets to avoid that text is truncated (e.g. in file chooser) + if( c.getComponentOrientation().isLeftToRight() ) + insets.right = 0; + else + insets.left = 0; + } + return insets; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index 33819569..a7f5c8c7 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -136,7 +136,16 @@ public class FlatUIUtils return FlatClientProperties.clientPropertyInt( c, FlatClientProperties.MINIMUM_HEIGHT, minimumHeight ); } - public static boolean isTableCellEditor( Component c ) { + public static boolean isCellEditor( Component c ) { + // check whether used as cell editor in file chooser + // Tree.cellEditor is set in sun.swing.FilePane.editFileName() + // Table.editor is set in JTable.GenericEditor constructor + String name = c.getName(); + if( "Tree.cellEditor".equals( name ) || "Table.editor".equals( name ) ) + return true; + + // for using combo box as cell editor in table + // JComboBox.isTableCellEditor is set in javax.swing.DefaultCellEditor(JComboBox) constructor return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) ); }