0
label_007= new JLabel("My Label");

In lieu of the above Label, My Label I want to insert an image in the same position.
How can I do that? I am just a novice in Java.
Please help

Darkak
  • 1
  • 1
    possible duplicate of [Java: how to add image to Jlabel?](http://stackoverflow.com/questions/3775373/java-how-to-add-image-to-jlabel) – Dennis Meng Oct 09 '14 at 15:56

2 Answers2

0
ImageIcon icon = new ImageIcon('image.png');
JLabel image = new JLabel();
image.setIcon(icon);

The above code should work.

  1. Make an image icon with an image file
  2. Make a JLabel
  3. Then set your JLabel's Icon
0

You can use ImageIcon for images:

ImageIcon ICON = new ImageIcon(URLClassLoader.class.getResource(IMAGE_PATH));
JLabel imageLabel = new JLabel();
imageLabel.setIcon(ICON);

URLClassLoader.class.getResource is using for packaging the application in runnable-jar file. The IMAGE_PATH is relative to your project folders/packages. for example if the image is in com.app.images package, the path will be /com/app/images/image.png.

If you're novice in Java and particularly in Swing, I encourage you to check my swing projects- Minesweeper and Pacman. They are well-documented, I built them when I learned Swing.

Good luck :)

Lidan
  • 93
  • 1
  • 7