How to add an Image to Form in java

Sachin D picture Sachin D · Dec 16, 2011 · Viewed 11k times · Source

I am designing a form in java using JDeveloper. I am new to JDeveloper. In JDeveloper tool I didn't found any option to directly add image to form like .Net. And I don't know how to add image to form manually. is there any other way to solve it out. So please help me to solve it.

Answer

COD3BOY picture COD3BOY · Dec 16, 2011

As simple as this :

image = ImageIO.read(new File(path));
JLabel picLabel = new JLabel(new ImageIcon(image));

Yayy! Now your image is a swing component ! add it to a frame or panel or anything like you usually do! Probably need a repainting too , like

jpanel.add(picLabel);
jpanel.repaint();