swing是否支持* .ico文件?
为摆动动作设置图像:
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
文件不会被渲染,只有png / jpg。
这是设计的吗?
制造商和版本可能会更改支持的类型,但您通常可以依赖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
本地,没有。
但是,您可能想看看image4j ,它为(IMHO)提供了极好的支持