Setting an image for a swing action :
Action action = ...
// ImageIcon icon = new ImageIcon(getClass().getResource("/icon.ico"));
ImageIcon icon = new ImageIcon(getClass().getResource("/icon_16x16.png"));
action.putValue(Action.SMALL_ICON, icon);
*.ico
files do not get rendered, only png/jpg.
Is this by design ?
The supported types might change by manufacturer and version, though you can usually count on PNG, JPG & GIF.
import javax.imageio.ImageIO;
public class QuickTest {
public static void main(String[] args) throws Exception {
String[] types = ImageIO.getReaderFileSuffixes();
System.out.println("This JRE supports image types:");
for (String type : types) {
System.out.println("Type: " + type);
}
}
}
This JRE supports image types:
Type: bmp
Type: jpg
Type: wbmp
Type: jpeg
Type: png
Type: gif
Natively, no.
How ever, you may like to take a look at image4j which provides (IMHO) excellent support for them
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With