diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c5bc7d..1e51434e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ FlatLaf Change Log - Use new chevron arrows in "Flat Light" and "Flat Dark" themes, but keep triangle arrows in "Flat IntelliJ" and "Flat Darcula" themes. (issue #7) +- Use bold font for default buttons in "Flat IntelliJ" and "Flat Darcula" + themes. - Hide label and button mnemonics on Mac. (issue #4) - If a JButton has an icon and no text, then it does not get a minimum width (usually 72 pixel) and the left and right insets are same as top/bottom insets diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index e86241c9..a1f51672 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -21,6 +21,7 @@ import static com.formdev.flatlaf.util.UIScale.scale; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; @@ -35,6 +36,7 @@ import javax.swing.LookAndFeel; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicButtonUI; import com.formdev.flatlaf.FlatLaf; @@ -56,6 +58,7 @@ import com.formdev.flatlaf.FlatLaf; * @uiDefault Button.default.focusedBackground Color optional * @uiDefault Button.default.hoverBackground Color optional * @uiDefault Button.default.pressedBackground Color optional + * @uiDefault Button.default.boldText boolean * @uiDefault Button.toolbar.hoverBackground Color * @uiDefault Button.toolbar.pressedBackground Color * @@ -79,6 +82,7 @@ public class FlatButtonUI protected Color defaultFocusedBackground; protected Color defaultHoverBackground; protected Color defaultPressedBackground; + protected boolean defaultBoldText; protected Color toolbarHoverBackground; protected Color toolbarPressedBackground; @@ -117,6 +121,7 @@ public class FlatButtonUI defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" ); defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" ); defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" ); + defaultBoldText = UIManager.getBoolean( "Button.default.boldText" ); toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" ); toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" ); @@ -199,6 +204,17 @@ public class FlatButtonUI if( isHelpButton( b ) ) return; + if( defaultBoldText && isDefaultButton( b ) && b.getFont() instanceof UIResource ) { + Font boldFont = g.getFont().deriveFont( Font.BOLD ); + g.setFont( boldFont ); + + int boldWidth = b.getFontMetrics( boldFont ).stringWidth( text ); + if( boldWidth > textRect.width ) { + textRect.x -= (boldWidth - textRect.width) / 2; + textRect.width = boldWidth; + } + } + paintText( g, b, textRect, text, b.isEnabled() ? getForeground( b ) : disabledText ); } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarculaLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarculaLaf.properties index fb4ac334..8b6b67fa 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarculaLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarculaLaf.properties @@ -18,6 +18,11 @@ # which is licensed under the Apache 2.0 license. Copyright 2000-2019 JetBrains s.r.o. # See: https://github.com/JetBrains/intellij-community/ +#---- Button ---- + +Button.default.boldText=true + + #---- Component ---- Component.focusWidth=2 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatIntelliJLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatIntelliJLaf.properties index 14f1dfbe..dcfb1b68 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatIntelliJLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatIntelliJLaf.properties @@ -22,6 +22,8 @@ Button.focusedBackground=null +Button.default.boldText=true + #---- CheckBox ----