SetIconImage from Images in the resource

泄露秘密 提交于 2019-12-11 05:39:30

问题


I have A swing Application that has an Image Folder in the resources. I use the Following Piece of code to access the Images:

btnDel = new JButton(new ImageIcon(getClass().getResource("/Recycling-Pool.png")));

This Methods Works fine For me in reference to Images for Components such as JLabels and JMenuItems. I have an Icon for the Application which I access using the Following Code:

setIconImage(getToolkit().getImage("Images/Free bsd.gif"));

This Also works fine for the Bar Icon, But I want the Icon Also Bundled together With the Apllication and I can't figure Out How to access the Icon Image for the Application Bar. Please Help.


回答1:


I figured Out the Answer. Sorry for Wasting your time. It will be like this:

setIconImage(getToolkit().getImage(getClass().getResource("/Free bsd.gif")));

This works fine for me for an embedded Image. :)



来源:https://stackoverflow.com/questions/15810335/seticonimage-from-images-in-the-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!