Button: use bold font for default buttons in "Flat IntelliJ" and "Flat Darcula" themes

This commit is contained in:
Karl Tauber
2019-10-05 11:03:18 +02:00
parent 17074eb16d
commit c87f5cb05f
4 changed files with 25 additions and 0 deletions

View File

@@ -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

View File

@@ -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 );
}

View File

@@ -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

View File

@@ -22,6 +22,8 @@
Button.focusedBackground=null
Button.default.boldText=true
#---- CheckBox ----