mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
Button: use bold font for default buttons in "Flat IntelliJ" and "Flat Darcula" themes
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
Button.focusedBackground=null
|
||||
|
||||
Button.default.boldText=true
|
||||
|
||||
|
||||
#---- CheckBox ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user