【发布时间】:2012-01-19 23:10:54
【问题描述】:
我有两个关于图标的问题。
我使用 ImageIcons 作为 JTree 上的默认图标。正如教程所建议的那样,我正在使用这种方法加载图标:
protected ImageIcon createImageIcon(String path) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
虽然为了让它工作,我必须将图像与我认为是混乱的源代码一起存储在文件中(但我读到它需要在 .jar 上运行)。有没有办法在项目文件夹而不是 src 上类似地加载图像?
还有一种方法可以自动将图像缩放到正确的尺寸以在 JTree 上显示吗?谢谢!
【问题讨论】: