i am developing a swing application using netbeans 7.1.2 . In this, i am using some image files. The image directory is currently in the dist folder. I want to attach the files with the jar file so that i can carry it anywhere as a SINGLE (jar)file. can anyone please help me with a solution?
Assuming your project is Maven-based, I would place the images in the src/main/resources
folder. Maven will automatically include the files in that folder into your JAR-file.
Otherwise, this blogpost will help you out.
Oi Mate
First Create a package(Say images) under Source Packages
copy all of your images to this package(when you create a package,a folder in the name of your package will be created inside your project src folder, so copy images to it)
You can access your Images from your program as
URL imageurl = getClass().getResource("/images/imagename");//assuming your package name is images
Image myPicture = Toolkit.getDefaultToolkit().getImage(imageurl);
JLabel piclabel = new JLabel(new ImageIcon( myPicture ));
piclabel.setBounds(0,0,myPicture.getWidth(null),myPicture.getHeight(null));
Now use this JLabel piclabel
简单方法:您可以将图像文件夹设置为classpath并通过eclipse导出jar文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.