guitar99
guitar99

Reputation: 1

image in a brand new jframe?

I am simply looking for a class that will create a new jframe displaying the image "rules.jpg" which is found in the src folder of my project.

edit: i worked out how to do this just there, but the image STILL wont display when i export it to a jar, does anyone have any tips?

Upvotes: 0

Views: 182

Answers (1)

jzd
jzd

Reputation: 23629

To load the image from a jar, you will need to access it differently. There is nice Swing tutorial for doing exactly that:

http://download.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

Here is some relevant code form the tutorial:

java.net.URL imageURL = myDemo.class.getResource("images/myImage.gif");
...
if (imageURL != null) {
    ImageIcon icon = new ImageIcon(imageURL);
}

Upvotes: 1

Related Questions