Browse Source

Button now respects bold font when calculating size.

Signed-off-by: weisj <weisj@arcor.de>
pull/44/head
weisj 5 years ago
parent
commit
4db70fdff8
  1. 12
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

12
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.ComponentUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View; import javax.swing.text.View;
import java.awt.*; import java.awt.*;
@ -136,6 +137,16 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene
config.restore(); 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 @Override
public void paint(final Graphics g, final JComponent c) { public void paint(final Graphics g, final JComponent c) {
GraphicsContext config = new GraphicsContext(g); GraphicsContext config = new GraphicsContext(g);
@ -147,6 +158,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene
} else if (g.getFont().isBold()) { } else if (g.getFont().isBold()) {
g.setFont(g.getFont().deriveFont(Font.PLAIN)); g.setFont(g.getFont().deriveFont(Font.PLAIN));
} }
String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g), String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g),
b.getWidth(), b.getHeight()); b.getWidth(), b.getHeight());

Loading…
Cancel
Save