Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get image from relative path

Tags:

java

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.

like image 735
Chan Pye Avatar asked Dec 30 '09 04:12

Chan Pye


People also ask

How do I find the path of an image?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How can I get the source of an image in HTML?

To use an image on a webpage, use the <img> tag. The tag allows you to add image source, alt, width, height, etc. The src is to add the image URL. The alt is the alternate text attribute, which is text that is visible when the image fails to load.

Why is img src not displaying?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.


1 Answers

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

like image 106
Chan Pye Avatar answered Nov 02 '22 09:11

Chan Pye