如何将来自spectified包的图像添加到标签,框架等 [英] how to add image from spectified package into label, frames etc

查看:193
本文介绍了如何将来自spectified包的图像添加到标签,框架等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在以下文件夹中添加图片:G:\ my java \DesktopApplication1 \ build \classes \desktopapplication1 \ resources。

I have images i want to add in the following folder: G:\my java\DesktopApplication1\build\classes\desktopapplication1\resources.

如何将此文件夹中的图像添加到我的标签或框架中?

How to go about adding image in this folder to my labels or frames?

推荐答案

一旦构建,图像通常会在Jar内。可以通过多种方式访问​​Jar中的资源,这里是一个。

Once built, the image will typically be inside a Jar. The resources in a Jar can be accessed a number of ways, here is one.

URL urlToImage = this.getClass().getResource(
    "/desktopapplication1/resources/the.png");
ImageIcon imageIcon = new ImageIcon(urlToImage);
JLabel ...

这篇关于如何将来自spectified包的图像添加到标签,框架等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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