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!

Recommended Answers

All 3 Replies

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?

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.