1

I'm using NetBeans 7.1 to code in Java. I have already created a JFrame filled with some labels, textbox and buttons. How can I do to import some image (JPG,PNG,etc...) from my PC into the same JFrame? On an specific location of the frame.

Roshna Omer
  • 687
  • 1
  • 11
  • 20
Johnny Dahdah
  • 995
  • 5
  • 15
  • 21
  • Did you create the code by hand or via the form editor? You may also want to take a look at [How to use labels](http://docs.oracle.com/javase/tutorial/uiswing/components/label.html) – MadProgrammer Mar 14 '13 at 02:59
  • 1
    *"How can I do to import some image (JPG,PNG,etc...) from my PC into the same JFrame?"* Did you miss the 3 posts about using images in desktop apps that were posted earlier ***today***? Please search on these things first! E.G. [this answer](http://stackoverflow.com/a/8958814/418556), [this answer](http://stackoverflow.com/a/14037856/418556) or [this answer](http://stackoverflow.com/a/5752471/418556).. – Andrew Thompson Mar 14 '13 at 03:00
  • @MadProgrammer Via form editor – Johnny Dahdah Mar 14 '13 at 03:00
  • possible duplicate of [Use animated GIF in desktop application](http://stackoverflow.com/questions/8958808/use-animated-gif-in-desktop-application) – Andrew Thompson Mar 14 '13 at 03:04
  • https://stackoverflow.com/questions/72159010/problem-using-icon-in-java-swing-netbeans could you assist me in resolving t issue? – Patrick Lee May 08 '22 at 07:44

3 Answers3

8
  1. Open the form in NetBeans form editor.
  2. Add a JLabel from the pallete to the form
  3. Select the label you just added and click the "..." button next to the icon property
  4. Fill out the properties.

It's normally best that the images reside within the project folder, makes deployment easier in the long run.

enter image description here

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

Make sure when you add the JLabel to use it from Swing Controls not AWT.

  • 1
    Perhaps add an example of the import statement for this answer? – Marshall Davis Mar 28 '17 at 19:34
  • There are two types of controls which you can use Label from: Swing Controls and AWT. Make sure you choose the Label under category Swing Control. To remove any confusion, make sure that your Label is initiated as 'new javax.swing.JLabel();' not 'new java.awt.Label();' – Michael.Abadir Mar 29 '17 at 18:08
  • Hats off to this answer, solved my issue. – Muhammad Ali Apr 25 '22 at 09:50
0
  1. Copy Image to your Netbeans project.
  2. Add new label to the frame.
  3. Select the label and Right click->Go to Properties.
  4. In Icon property select image by down arrow as shown in image.

enter image description here

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25