Java allows you to add pictures directly to JLabels.
The following code will display a picture of a dog in the JLabel (assuming, of course, you have a file dog.jpg). Watch out for upper and lower case letters in your picture paths!
```java
public class MyFrame extends JFrame {
MyFrame() {
this.setSize(250,150);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("M:/dog.jpg");
JLabel lbl = new JLabel(img);
this.add(lbl);
}
}
```
You can add text to a picture, and set the position of the text.
![[pictureofdoggui.png|300]]
```java
ImageIcon img = new ImageIcon("M:/dog.jpg");
JLabel lbl = new JLabel("Picture of Dog", img, JLabel.CENTER);
lbl.setVerticalTextPosition(JLabel.BOTTOM);
lbl.setHorizontalTextPosition(JLabel.CENTER);
this.add(lbl);
```
## Image Locations
It's a good idea to store all your images in a folder called, say, img. You can place this folder in the root of your eclipse project and refer to it using a [[File Paths|relative file path]] as follows:
```java
img1 = new ImageIcon("img/pisa.jpg");
```
## Checking Image is Loaded
Unusually for Java, your code will still compile and the program run even if the image is not found. This can be frustrating: if your images are missing you may wonder whether this is due to the wrong path or something else.
A handy trick to check if an image has been loaded is to check the width of the loaded image, as follows:
```java
img1 = new ImageIcon("img/pisa.jpg");
if(img.getIconWidth() == -1) System.out.println("Image not found");
```