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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.io.Serial;
/**
* A button with an icon and a translation key.
* @author Dan Royer
*/
public class ButtonIcon extends JButton {
private static final Logger logger = LoggerFactory.getLogger(ButtonIcon.class);
public ButtonIcon(String translation, String iconPath) {
super();
setText(translation);
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;
}
}
}
94ff58e1aThis file is pinned to the selected release. Download the original to open it in your design tool.