Reputation: 53
lblImage = new javax.swing.JLabel();
lblImage.setIcon(new javax.swing.ImageIcon("E:..path...png"));
I added the file like this. I know it is not accessing the path when running the jar file. Help me how to import a image file to java project in Netbeans.
Upvotes: 3
Views: 1449
Reputation: 2133
Create the image folder in the src folder, put the images in the folder and give the relative path for creating the image icon object
jLabel1.setIcon(new ImageIcon(getClass().getResource("/image/img1.jpg")));
then rebuild the jar .it will access the images from the jar
Upvotes: 1
Reputation: 2638
Recommended way is place images inside resource
folders and use it as below:
jLabel1.setIcon(new ImageIcon(getClass().getResource("/path/to/image.png")));
Read More: NetBeans Doc
Upvotes: 6