From 4db70fdff84cfec637b9f8dafe8735a3d16fe7c8 Mon Sep 17 00:00:00 2001 From: weisj Date: Mon, 17 Feb 2020 12:29:49 +0100 Subject: [PATCH] Button now respects bold font when calculating size. Signed-off-by: weisj --- .../github/weisj/darklaf/ui/button/DarkButtonUI.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index 740d2066..e5cc3a8e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java @@ -34,6 +34,7 @@ import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicButtonUI; +import javax.swing.plaf.basic.BasicGraphicsUtils; import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.View; import java.awt.*; @@ -136,6 +137,16 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene config.restore(); } + @Override + public Dimension getPreferredSize(final JComponent c) { + AbstractButton b = (AbstractButton) c; + Font oldFont = b.getFont(); + b.setFont(b.getFont().deriveFont(Font.BOLD)); + Dimension size = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap()); + b.setFont(oldFont); + return size; + } + @Override public void paint(final Graphics g, final JComponent c) { GraphicsContext config = new GraphicsContext(g); @@ -147,6 +158,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } else if (g.getFont().isBold()) { g.setFont(g.getFont().deriveFont(Font.PLAIN)); } + String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());