0

The code i used in JGrasp to show the image is not working in Netbeans

The code i used in JGrasp is

final ImageIcon icon1 = new ImageIcon("image/money.gif");
JOptionPane.showMessageDialog(null, " blah blah", "Text", +
JOptionPane.INFORMATION_MESSAGE,   icon1);

And if i wanted to show an image in JOptionPane.showInputDialog would it be the same for JOptionPane.showMessageDialog ?

Any help is greatly appreciated!

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by NormR1
0

Make sure the image is in the location that the program is looking for it to be.
Where is the image folder? Is it in the current directory for the program when it is executed?

0

I don't think that the location is the problem because when i do this

menuPic = new JButton();           
menuPic = new javax.swing.JButton();
menuPic.setIcon(new javax.swing.ImageIcon(getClass().getResource("image/money.gif")));

It shows the image fine, but when i try to add an image to my joptionpane it doesn't show anything

Edited by iEpic

0

If the image is where the code is looking for it, the code will work. If the image is not there, the code fails.

The getResource() method uses the classpath to find the image.
The path via a String uses the current directory to find the image.

Where is the classpath and the current directory when the code is executed?
Try this code to see:

      System.out.println(System.getProperty("user.dir"));   // Show the current directory
      System.out.println(System.getProperty("java.class.path"));  // show the classpath

Edited by NormR1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.