From 4aee1fd6f54a9db74463e3f8a71c09a79392b891 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 1 Jul 2017 20:37:11 +0200 Subject: [PATCH] getLargestIconHeightForButton now saves the original icon + text, then restores those values once done calculating the height --- src/dorkbox/util/SwingUtil.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dorkbox/util/SwingUtil.java b/src/dorkbox/util/SwingUtil.java index 7441f99..8512979 100644 --- a/src/dorkbox/util/SwingUtil.java +++ b/src/dorkbox/util/SwingUtil.java @@ -39,6 +39,7 @@ import java.net.URISyntaxException; import java.util.Locale; import javax.swing.AbstractButton; +import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; @@ -223,6 +224,11 @@ class SwingUtil { // large // myTextField.putClientProperty("JComponent.sizeVariant", "large"); + // save the icon + text + Icon icon = button.getIcon(); + String text = button.getText(); + + button.setText("`Tj|┃"); // `Tj|┃ are glyphs that are at the top/bottom of the fontset (usually)); int minHeight = 0; int iconSize = 0; for (int i = 1; i < 128; i++) { @@ -232,6 +238,8 @@ class SwingUtil { int height = (int) button.getPreferredSize() .getHeight(); +// System.out.println(imageIcon.getIconHeight() + "x" + imageIcon.getIconHeight() + " icon \t>>>>>>>>> " + height + "px tall item"); + if (minHeight == 0) { minHeight = height; } else if (minHeight != height) { @@ -242,6 +250,10 @@ class SwingUtil { iconSize = imageIcon.getIconHeight(); } + // restore original values + button.setIcon(icon); + button.setText(text); + return iconSize; }