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.
Asked
Active
Viewed 7.2k times
1

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 Answers
8
- Open the form in NetBeans form editor.
- Add a
JLabel
from the pallete to the form - Select the label you just added and click the "..." button next to the
icon
property - Fill out the properties.
It's normally best that the images reside within the project folder, makes deployment easier in the long run.

MadProgrammer
- 343,457
- 22
- 230
- 366
-
1Thank you very much!! So easy. I'm new to Java JFrames as you can see. Thanks again! – Johnny Dahdah Mar 14 '13 at 03:12
-
-
1@AlitheDev 1. Make sure you're using a `JLabel`; 2. Make sure it's selected. See the added screen shoot – MadProgrammer Apr 25 '22 at 11:50
1
Make sure when you add the JLabel to use it from Swing Controls not AWT.

Michael.Abadir
- 11
- 2
-
1Perhaps 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
-
0
- Copy Image to your Netbeans project.
- Add new label to the frame.
- Select the label and Right click->Go to Properties.
- In Icon property select image by down arrow as shown in image.

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