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.plaf.basic.BasicButtonListener;
import com.github.weisj.darklaf.util.PropertyKey;
public class DarkButtonListener extends BasicButtonListener {
private final DarkButtonUI ui;
@ -77,12 +75,8 @@ public class DarkButtonListener extends BasicButtonListener {
super.propertyChange(e);
AbstractButton b = (AbstractButton) e.getSource();
String key = e.getPropertyName();
if (key.startsWith("JButton.")
|| PropertyKey.FOCUSABLE.equals(key)
|| AbstractButton.TEXT_CHANGED_PROPERTY.equals(key)) {
b.revalidate();
b.doLayout();
b.repaint();
if (key.startsWith("JButton.")) {
b.invalidate();
}
}
}

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;
paintButtonBackground(g, c);
if (ButtonConstants.isDefaultButton(b)) {
g.setFont(g.getFont().deriveFont(Font.BOLD));
} else if (g.getFont().isBold()) {
g.setFont(g.getFont().deriveFont(Font.PLAIN));
Font font = g.getFont();
if (ButtonConstants.isDefaultButton(b) && !font.isBold()) {
g.setFont(font.deriveFont(Font.BOLD));
} else if (font.isBold()) {
g.setFont(font.deriveFont(Font.PLAIN));
}
String text = layout(b, c, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());

Loading…
Cancel
Save