如何在java runnable jar中加载图像? [英] how to load the images in java runnable jar?

查看:87
本文介绍了如何在java runnable jar中加载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将项目转换为runnable jar相同的系统时,图像将在输出中加载。但是当我在另一个系统中尝试时,图像无法加载?如何给出图像URL,而不是使用c:?请帮忙吗?

When I convert my project into runnable jar the same system, the image is loading in the output. But when I tried in another system, the image failed to load? how to give the image URL rather then using c: ?please help on this?

JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL);

JButton capturebut = new JButton(new ImageIcon("C:\\sampleprojects\\
       compare\\shankar\\src\\capture.gif"));

capturebut.setToolTipText("Capture");

toolbar.add(capturebut);


推荐答案

使用 getResourceAsStream

http://download.oracle.com/javase/tutorial/uiswing/components/icon.html

http://www.jugpadova.it/articles/2006/02/05 / access-a-resource-a-jar

这篇关于如何在java runnable jar中加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆