Results 1 to 6 of 6
  1. #1
    shahid0627 is offline Member
    Join Date
    Aug 2009
    Posts
    16
    Rep Power
    0

    Default How can I add image to a JPanel using netbeans

    I want to add image to a Panel by using Netbeans.But I can't find the way.Plz give urgent suggestion.
    Thanks,
    Shahid0627

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Reading some tutorials should help.
    Here is one.

  3. #3
    shahid0627 is offline Member
    Join Date
    Aug 2009
    Posts
    16
    Rep Power
    0

    Default

    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.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hrm/orange_new_06.gif")));

    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)

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    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

  5. #5
    shahid0627 is offline Member
    Join Date
    Aug 2009
    Posts
    16
    Rep Power
    0

    Default

    Oh, it works.
    Thanks zweibieren.

  6. #6
    selva.bics is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default 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

Similar Threads

  1. Replies: 4
    Last Post: 08-28-2009, 06:50 PM
  2. Add Image to JPanel
    By Seonix in forum AWT / Swing
    Replies: 1
    Last Post: 08-12-2009, 01:54 PM
  3. Image appear at random co-ord within jpanel
    By IHateNetbeans in forum New To Java
    Replies: 1
    Last Post: 04-30-2009, 07:06 PM
  4. How to display image from byte array in JPANEL
    By waqasdaar in forum AWT / Swing
    Replies: 0
    Last Post: 03-22-2009, 12:11 AM
  5. how to set image to a jpanel
    By masa in forum AWT / Swing
    Replies: 1
    Last Post: 03-02-2009, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •