Browse Source

less repaints when updating text on buttons.

pull/170/head
weisj 5 years ago
parent
commit
a29f03da7e
  1. 10
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java
  2. 9
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

10
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java

@ -31,8 +31,6 @@ import java.beans.PropertyChangeEvent;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonListener; import javax.swing.plaf.basic.BasicButtonListener;
import com.github.weisj.darklaf.util.PropertyKey;
public class DarkButtonListener extends BasicButtonListener { public class DarkButtonListener extends BasicButtonListener {
private final DarkButtonUI ui; private final DarkButtonUI ui;
@ -77,12 +75,8 @@ public class DarkButtonListener extends BasicButtonListener {
super.propertyChange(e); super.propertyChange(e);
AbstractButton b = (AbstractButton) e.getSource(); AbstractButton b = (AbstractButton) e.getSource();
String key = e.getPropertyName(); String key = e.getPropertyName();
if (key.startsWith("JButton.") if (key.startsWith("JButton.")) {
|| PropertyKey.FOCUSABLE.equals(key) b.invalidate();
|| AbstractButton.TEXT_CHANGED_PROPERTY.equals(key)) {
b.revalidate();
b.doLayout();
b.repaint();
} }
} }
} }

9
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -158,10 +158,11 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
AbstractButton b = (AbstractButton) c; AbstractButton b = (AbstractButton) c;
paintButtonBackground(g, c); paintButtonBackground(g, c);
if (ButtonConstants.isDefaultButton(b)) { Font font = g.getFont();
g.setFont(g.getFont().deriveFont(Font.BOLD)); if (ButtonConstants.isDefaultButton(b) && !font.isBold()) {
} else if (g.getFont().isBold()) { g.setFont(font.deriveFont(Font.BOLD));
g.setFont(g.getFont().deriveFont(Font.PLAIN)); } else if (font.isBold()) {
g.setFont(font.deriveFont(Font.PLAIN));
} }
String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight()); String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());

Loading…
Cancel
Save