How to put pictures in NetBeans? - java

I'm making a game in NetBeans and I have to put some pictures and when I start the program they are there, but when I do clean and build pictures are not in the JAR file. Can someone help me? I'm not using JFrame form.

I am using JFrame and I think it's similar to whatever you are using while it's on netbeans
you have to put them in src folder
right click on the jLabel (if you using JFrame you have to add jLabel )
choose properties
choose icon
choose image within project
and you will find all pictures in src folder
this way when you share the JAR file the pictures will be inside it
but if you chose External image in step 5 you will use just the path of the image ( I think here's your problem )

Related

JFrame background image. "absolute path in a file system"

I am creating a GUI using WindowBuilder in Eclipse and I searched for ways on how to add background images. Some suggested the use of a JLabel. There is an option in for labels called icon and I can set that to an image in an "absolute path in a file system" however this option gives a warning to never use in real application. I think this is because the program cannot find the image if the app is opened in another PC.
How can I add an image that can be used in a deployed application?

Exporting a java game into an executable jar file in eclipse - not working

Hello I have made a simple game where my sprite can move around a tiny green map and can't go off of it. It has several menu buttons, and it runs perfectly in eclipse. I have my own graphics, and am using LWJGL, and slick 2d.
This is what my package explorer looks like in eclipse : http://puu.sh/2x1Sx
It seems to not be exporting my pictures in the resource file. I've tried exporting it as a runnable jar file, and as a regular jar file. I have the main class as Game.java in my manifest file, and it does nothing on double click. Any help would be appreciated :) Thanks
Check if you're exporting the res folder
To be able to export a folder, you need to add it as a source folder
After that you will see the folder in the Order and Export tab
in your game class use the following:
new Image(Game.class.getResourceAsStream("filename"),
"filename",
false);
I found a youtube video on how to make a jar file from slick/lwjgl projects in eclipse link is here : http://www.youtube.com/watch?v=K6K2d6LGvu8

Project Not showing icons after Executeable jar file

I am running net beans application, when i run it via net beans it is showing icons properly...but when i convert it to executable .exe it is not showing icons..i did a lot of research to solve this problem but everything gone in vain. This is the best method i have saw to get icons dynamically....
My icon heraricy is src/com/idoccsmain/icons/ and all of my icons inside the "icons" folder
ImageIcon icon = new ImageIcon(Main.Class.getClass().getResource("/com/idoccsmain/icons/"+"add_icon.p‌​ng")
through this line i am getting all of my different icons..can any one suggest any solution for me....?
Thanks guys for responses with your help i came up with this... solution
put images in Src folder e.g src/icons/ and inside icons folder.
Than use this line in netbeans to get your images working......
ImageIcon icon = new ImageIcon(getClass().getResource("/icons/AnyIconName.png"));
and make sure use this line for each icon.
For J2ME Application
Check this image carefully, Right Click on project then Properties.
Select Application Descriptor and then select MIDlets
If it is showing anything there, like showing in this picture then edit accordingly.
NOTE : - In the above scenario src/myproject/ where icon and .java exist.
===== UPDATE =====
Desktop based executable jar
Then use, this code
this.getFrame().setIconImage(new imageIcon(getClass().getClassLoader().getResource("add_icon.p‌​ng")));
Note: this line only works if the images are in the root of the jar file. If not, you have to specify the folder on the string:
getResource("yourfolder/add_icon.p‌​ng")
You might also interested for this link to create executable java file and also associate icon to it.

Where should I store images (and other files) to be used by my program in Java?

I'm trying to create a (very) simple GUI program which allows the user to select from different radio buttons to display an image in a JLabel. The code I'm using is this:
JLabel imageLabel = new JLabel();
imageLabel.setIcon(new ImageIcon("images/Dog"));
My question is, where do I put this "images" folder? When I put it in the src and the bin folder, the images still didn't load. I ended up trying the following code which worked when I used the bin folder:
imageLabel.setIcon(new ImageIcon(getClass().getResource("images/Dog")));
The problem is, from what I understand the bin folder isn't supposed to be used for these files? Also, I'm pretty sure the images folder I put in there got deleted (which would be a pretty good reason not to use it...).
I'm sending the directory to my professor, so I don't want the file path to work exclusively on my computer.
PS I'm using Eclipse, if that matters.
Just put it in the project's folder. Example:
You would put your images folder where my "del_icon" image is. Just right in the folder.

Java - Adding Images to JButtons

I want to add images to JButtons. Here is the code I am using:
The images are in a folder called "Images", which happens to be in the source package of the application. The size of the JButtons is adjusted correctly, however no image is displayed in the button. Can someone help me solve this problem please? Thanks :)
Try create_ImageIcon(Button_NewFile, "src/Images/New File.png");
When you create an ImageIcon, it searches for relative paths where the application is launched. Normally this is in the folder where src folder is located. But have in mind that when you run it as an independent application.

Categories

Resources