Setting Background Image

Setting a Background Image in Netbeans IDE


Simplified instructions:
Create a JFrame,
On design view, right click the JFrame, click Layout => Null
Create a JLabel, resize it so it covers your JFrame.
Right Click the JLabel, Find Icon and click on the (...) button.
Pick a picture by clicking the Import to project button, then click finish.
In the Navigator pane, (Bottom left by default, if disabled go to the Windows tab of your Netbeans IDE and enable it.) right click on your JFrame and select Change Order. Then just put every object on top of your JLabel that contains your background image. You're done!

Specific Instructions:
Step 1: You must create the application form. Do this by clicking, File -> New Project ->  Finish.

Step 2: In the Projects field, (the top left, by default) expand the Project's tree by clicking on the + sign next to it. Then right click on the Source packages node and click New => JFrame Form => Finish.

Step 3: Right click the JFrame and select Set Layout => Null.

Step 4:  In the JFrame, create a JLabel using the Palette, (the Palette is top right by default) by clicking and dragging Label to the JFrame area.

Step 5: Resize your JLabel so that it covers the entirety of your JFrame, because you will need your background image to occupy that space.

Step 6:  Right click the JLabel, click properties, navigate to the icon property, and select the (...) button to the right of it. Then in the popup window that appears, click Import to Project and select the picture you'd like to add.

DETAILED VIDEO BELOW









38 comments:

  1. Thank You so much. I've searched alot with no vain but This is the simplest way I've found.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. It is working for me with OpenJDK Java 7 and NetBeans IDE 7 in linux Ubuntu 12.04, but with little bit different method, in step3 i setup Set Layout > Absolut Design. working like a charm.........thank you very much for the clue...

    ReplyDelete
  4. At last we shud right click on the swing controls like buttons,textfields and select move down.

    ReplyDelete
  5. 1 problem down thanks to this tutorial

    ReplyDelete
  6. But, How to add a background image that auto-resizes when screen resolution is changed?

    ReplyDelete
  7. this code very useful to me thank u very much

    ReplyDelete
  8. Thank you very much dude.... this is awesome....

    ReplyDelete
  9. Thanks! But now when i run the window has to be resized to show the image. How do I fix that?

    ReplyDelete
  10. Really Great Boss.............at last i can do it. Thanks Boss

    ReplyDelete
    Replies
    1. @ Safiqul, Dhaka, Bangladesh.

      Delete
  11. fight me irl +44 7525 482788

    ReplyDelete
  12. great blog.. really appreciate it :)

    ReplyDelete
  13. how to make the image fits to screen.. i found this easy but image not getting enlarged to screen size

    ReplyDelete
    Replies
    1. image cannot be enlatrged... you have to resize it before adding it to jlabel using paint or photoshop..

      Delete
  14. Whenever i add any other component on jlabel background it get invisible...help

    ReplyDelete
  15. OK. for there super and all thing ok,but I need to the image changing when I do something.Like when the user choosed 2nd item from JComboBox or another thing wallpaper will be changed.
    Does anyone have an idea?

    Soooo Sorry for my bad English :)

    ReplyDelete
  16. For change the same image on JLabel (used for background) just change image url or path with new image path or url.
    :)

    ReplyDelete
  17. but the picture losts a rest of it. how can i do?

    ReplyDelete
  18. how to set image for windows desktop

    ReplyDelete
  19. very helpful,thanks a lot

    ReplyDelete