getLargestIconHeightForButton now saves the original icon + text, then

restores those values once done calculating the height
This commit is contained in:
nathan 2017-07-01 20:37:11 +02:00
parent 46ae5cbc78
commit 4aee1fd6f5

View File

@ -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;
}