问一个JLabel上贴图遇到的问题

hhwolf76 2011-11-27 12:25:57
我的代码放在project这个package下,使用
ImageIcon topIcon = new ImageIcon(this.getClass().getResource("../images/test.jpg"));
这个方法找到图片。目录结构为

/work/bin/project/[all .class files]
/images/test.jpg
/src/project/[all .java files]

现在这个方法是可行的。但是我想把images目录直接放在/work文件夹下,然后用以下方法
ImageIcon topIcon = new ImageIcon(this.getClass().getResource("../../images/test.jpg"));
这个就行不通,为什么呢?该怎样呢?谢谢
...全文
45 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhwolf76 2011-11-28
  • 打赏
  • 举报
回复
可是我没有点数了啊
wang7535067 2011-11-27
  • 打赏
  • 举报
回复
用相对路径

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧