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.
Asked
Active
Viewed 1.3k times
4 Answers
7
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();

Ömer Erden
- 7,680
- 5
- 36
- 45

COD3BOY
- 11,964
- 1
- 38
- 56
-
+1 This is easy and flexible; see also [`ImageApp`](http://stackoverflow.com/a/5129757/230513) for a different approach. – trashgod Dec 16 '11 at 11:23
2
Don't know about JDeveloper but in code you have following possibilities:
- Create an
ImageIcon
of the image then set that to a jLabel and add jLabel to your frame. Override{Not sure about this}paintComponents()
of your frame to draw image using Graphics in it.- Override
paintComponent()
of some panel or any other component to draw image using Graphics in it and then add that component to frame..

Harry Joy
- 58,650
- 30
- 162
- 207
-
*"2. Override paintComponent() of your frame"* `JFrame` has no `paintComponent()` method. – Andrew Thompson Dec 16 '11 at 06:41
-
@AndrewThompson: I think its paintComponents() for JFrame. But still not sure. – Harry Joy Dec 16 '11 at 06:52
2
You can use Labels as Sanjay says.
also using layered pane you can use as background image.

user999822
- 445
- 1
- 9
- 17