Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
package com.marginallyclever.convenience;
import com.marginallyclever.makelangelo.Translator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
public class ButtonIcon extends JButton {
private static final long serialVersionUID = 6329805223648415348L;
private static final Logger logger = LoggerFactory.getLogger(ButtonIcon.class);
public ButtonIcon(String translationKey, String iconPath) {
super();
if (translationKey != null && !translationKey.isEmpty() && !translationKey.isBlank()) {
setText(Translator.get(translationKey));
}
setIcon(createImageIcon(iconPath));
}
public void replaceIcon(String iconPath) {
setIcon(createImageIcon(iconPath));
}
/**
* @return an ImageIcon, or null if the path was invalid.
*/
private ImageIcon createImageIcon(String path) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
logger.warn("Failed to load icon {}", path);
return null;
}
}
}
cfb67a76cThis file is pinned to the selected release. Download the original to open it in your design tool.