Get the image of the relative path
source link: https://www.codesd.com/item/get-the-image-of-the-relative-path.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Get the image of the relative path
In my project I have 2 packages. images - contain images and notification - contain java files
In notification/main.java I get Image object from image using this code
Image image = Toolkit.getDefaultToolkit().getImage("/images/key-16x16.png");
and I can't get image.
How can I fix this bug.
I'm using Netbeans to develop Java desktop application and I have solved my problem.
Image image = new ImageIcon(this.getClass().getResource("/images/bell-icon16.png")).getImage();
"this" is a class extends JFrame
Related Articles
How to get the relative path of a visual studio file?
Get the relative path of the full path
How to get the relative path of UriInfo
How to get the relative path of the file to a folder using java
How to get the relative path as a string of an image file in the same project folder?
How do I get the relative path of a project from another project in the same solution?
Get the relative path of the file?
Get the relative path of RegistryKey
how to get the relative path of a resource in a j2ee project
How do I get the relative path of ASP.NET content
how to get an image from a relative path
Get the relative path of the XML file located in another project, but the same solution
When developing the eclipse plugin, can I get the absolute path of jar files using & ldquo; Add Jars & rdquo;
Find the relative path of the Java application
Android captures the image and get the real path
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK