From a29f03da7e86285a6d6578ab9061cbf017cd8d75 Mon Sep 17 00:00:00 2001 From: weisj Date: Mon, 11 May 2020 16:18:54 +0200 Subject: [PATCH] less repaints when updating text on buttons. --- .../weisj/darklaf/ui/button/DarkButtonListener.java | 10 ++-------- .../github/weisj/darklaf/ui/button/DarkButtonUI.java | 9 +++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java index fe5529f1..9c95e3f1 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonListener.java +++ b/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(); } } } 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 f9f5f398..0ce988ec 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 @@ -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());