Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an Image to Form in java

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.

like image 929
Sachin D Avatar asked Dec 21 '22 04:12

Sachin D


2 Answers

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(); 
like image 125
COD3BOY Avatar answered Dec 24 '22 03:12

COD3BOY


Don't know about JDeveloper but in code you have following possibilities:

  1. Create an ImageIcon of the image then set that to a jLabel and add jLabel to your frame.
  2. Override paintComponents() of your frame to draw image using Graphics in it. {Not sure about this}
  3. Override paintComponent() of some panel or any other component to draw image using Graphics in it and then add that component to frame..
like image 33
Harry Joy Avatar answered Dec 24 '22 03:12

Harry Joy