I try the same code in JCreator,it works but not in netbeans.Whenever I want to add image to any swing controls(such as JButton) it shows exceptions.
here is the code:jButton1 = new javax.swing.JButton();

jButton1.setText("jButton1");
and here is the exception:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:138)
at hrm.NewJFrame.initComponents(NewJFrame.java:35)
at hrm.NewJFrame.<init>(NewJFrame.java:18)
at hrm.NewJFrame$1.run(NewJFrame.java:64)
at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 461)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)

08-31-2009, 10:19 AM

zweibieren

getResource is not finding "/hrm/orange_new_06.gif"

When I had this sort of problem it was because I had not done a "clean and build" on the project. The build will copy the image from the source tree to the destination tree. getResource looks in the destination tree

08-31-2009, 07:29 PM

shahid0627

Oh, it works.Thanks zweibieren.

09-01-2009, 07:56 AM

selva.bics

Adding image

To add image in Jpanel u have to place lable in the Jpanel ,
in the lable property, there will option called icon through this u
can add image and u can resize as u wish