diff --git a/CHANGELOG.md b/CHANGELOG.md index 8157d29d..bfd0bfcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ FlatLaf Change Log pixels. On Windows, it is now 10 pixels. (issue #131) - ToolTip: Do not show empty tooltip component if tooltip text is an empty string. (issue #134) +- Button: Support specifying button border width. ## 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 4191102f..bfad3254 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 @@ -43,24 +43,24 @@ import com.formdev.flatlaf.util.DerivedColor; * Border for various components (e.g. {@link javax.swing.JTextField}). * * There is empty space around the component border, if Component.focusWidth is greater than zero, - * which is used to paint focus border. + * which is used to paint outer focus border. * - * Because there is empty space (if focus border is not painted), + * Because there is empty space (if outer focus border is not painted), * UI delegates that use this border (or subclasses) must invoke * {@link FlatUIUtils#paintParentBackground} to paint the empty space correctly. * - * @uiDefault Component.focusWidth int - * @uiDefault Component.innerFocusWidth int or float - * @uiDefault Component.focusColor Color - * @uiDefault Component.borderColor Color - * @uiDefault Component.disabledBorderColor Color - * @uiDefault Component.focusedBorderColor Color + * @uiDefault Component.focusWidth int + * @uiDefault Component.innerFocusWidth int or float + * @uiDefault Component.focusColor Color + * @uiDefault Component.borderColor Color + * @uiDefault Component.disabledBorderColor Color + * @uiDefault Component.focusedBorderColor Color * - * @uiDefault Component.error.borderColor Color - * @uiDefault Component.error.focusedBorderColor Color - * @uiDefault Component.warning.borderColor Color - * @uiDefault Component.warning.focusedBorderColor Color - * @uiDefault Component.custom.borderColor Color + * @uiDefault Component.error.borderColor Color + * @uiDefault Component.error.focusedBorderColor Color + * @uiDefault Component.warning.borderColor Color + * @uiDefault Component.warning.focusedBorderColor Color + * @uiDefault Component.custom.borderColor Color * * @author Karl Tauber */ @@ -93,16 +93,18 @@ public class FlatBorder float arc = isCellEditor ? 0 : scale( (float) getArc( c ) ); Color outlineColor = getOutlineColor( c ); + // paint outer border if( outlineColor != null || isFocused( c ) ) { - float innerFocusWidth = !(c instanceof JScrollPane) - ? (outlineColor != null ? innerOutlineWidth : this.innerFocusWidth) + float innerWidth = !(c instanceof JScrollPane) + ? (outlineColor != null ? innerOutlineWidth : innerFocusWidth) : 0; g2.setColor( (outlineColor != null) ? outlineColor : getFocusColor( c ) ); - FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth, - scale( (float) getLineWidth( c ) ) + scale( innerFocusWidth ), arc ); + FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, + focusWidth, borderWidth + scale( innerWidth ), arc ); } + // paint border g2.setPaint( (outlineColor != null) ? outlineColor : getBorderColor( c ) ); FlatUIUtils.paintComponentBorder( g2, x, y, width, height, focusWidth, borderWidth, arc ); } finally { @@ -110,6 +112,10 @@ public class FlatBorder } } + /** + * Returns the outline color of the component border specified in client property + * {@link FlatClientProperties#OUTLINE}. + */ protected Color getOutlineColor( Component c ) { if( !(c instanceof JComponent) ) return null; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java index 41fb2478..5fc802d4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonBorder.java @@ -42,6 +42,7 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault Button.default.hoverBorderColor Color optional * @uiDefault Button.default.focusedBorderColor Color * @uiDefault Button.default.focusColor Color + * @uiDefault Button.borderWidth int * @uiDefault Button.default.borderWidth int * @uiDefault Button.toolbar.margin Insets * @uiDefault Button.toolbar.spacingInsets Insets @@ -62,6 +63,7 @@ public class FlatButtonBorder protected final Color defaultHoverBorderColor = UIManager.getColor( "Button.default.hoverBorderColor" ); protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" ); protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" ); + protected final int borderWidth = UIManager.getInt( "Button.borderWidth" ); protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" ); protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" ); protected final Insets toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" ); @@ -134,7 +136,7 @@ public class FlatButtonBorder @Override protected int getBorderWidth( Component c ) { - return FlatButtonUI.isDefaultButton( c ) ? defaultBorderWidth : super.getBorderWidth( c ); + return FlatButtonUI.isDefaultButton( c ) ? defaultBorderWidth : borderWidth; } @Override 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 42ea107f..33819569 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 @@ -210,7 +210,7 @@ public class FlatUIUtils * Paints an outer border, which is usually a focus border. *
* The outside bounds of the painted border are {@code x,y,width,height}. - * The line width of the painted border is {@code focusWidth + lineWidth}. + * The line thickness of the painted border is {@code focusWidth + lineWidth}. * The given arc diameter refers to the inner rectangle ({@code x,y,width,height} minus {@code focusWidth}). * * @see #paintComponentBorder @@ -219,6 +219,9 @@ public class FlatUIUtils public static void paintComponentOuterBorder( Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc ) { + if( focusWidth + lineWidth == 0 ) + return; // nothing to paint + double systemScaleFactor = UIScale.getSystemScaleFactor( g ); if( systemScaleFactor != 1 && systemScaleFactor != 2 ) { // paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175% @@ -255,6 +258,7 @@ public class FlatUIUtils *
* The outside bounds of the painted border are * {@code x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)}. + * The line thickness of the painted border is {@code lineWidth}. * The given arc diameter refers to the painted rectangle (and not to {@code x,y,width,height}). * * @see #paintComponentOuterBorder @@ -263,6 +267,9 @@ public class FlatUIUtils public static void paintComponentBorder( Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc ) { + if( lineWidth == 0 ) + return; // nothing to paint + double systemScaleFactor = UIScale.getSystemScaleFactor( g ); if( systemScaleFactor != 1 && systemScaleFactor != 2 ) { // paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175% diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index ca60fa56..776d557c 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -135,6 +135,7 @@ Button.rollover=true Button.defaultButtonFollowsFocus=false [win]Button.defaultButtonFollowsFocus=true +Button.borderWidth=1 Button.default.borderWidth=1 Button.toolbar.margin=3,3,3,3 diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt index 73055251..1f81a626 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -65,6 +65,7 @@ Button.arc 6 Button.background #4c5052 javax.swing.plaf.ColorUIResource [UI] Button.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatButtonBorder [UI] Button.borderColor #5e6060 javax.swing.plaf.ColorUIResource [UI] +Button.borderWidth 1 Button.darkShadow #7e7e7e javax.swing.plaf.ColorUIResource [UI] Button.default.background #365880 javax.swing.plaf.ColorUIResource [UI] Button.default.boldText true diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt index 4058f8b0..785c40e6 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -65,6 +65,7 @@ Button.arc 6 Button.background #ffffff javax.swing.plaf.ColorUIResource [UI] Button.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatButtonBorder [UI] Button.borderColor #c4c4c4 javax.swing.plaf.ColorUIResource [UI] +Button.borderWidth 1 Button.darkShadow #9e9e9e javax.swing.plaf.ColorUIResource [UI] Button.default.background #ffffff javax.swing.plaf.ColorUIResource [UI] Button.default.borderColor #4f9ee3 javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 6cd70c7b..c5ff3e84 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -12,6 +12,7 @@ Button.arc Button.background Button.border Button.borderColor +Button.borderWidth Button.darkShadow Button.default.background Button.default.boldText