How to add image to form in java

I am developing a form in java using JDeveloper. I am new to JDeveloper. In the JDeveloper tool, I did not find the ability to directly add an image to a .Net type form. And I do not know how to add an image to a form manually. is there any other way to solve it. So please help me solve this problem.

+4
source share
4 answers

The easiest way is:

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 something similar as usual. Maybe you need repainting, for example

  jpanel.add(picLabel); jpanel.repaint(); 
+7
source

I do not know about JDeveloper, but in the code you have the following features:

  • Create an ImageIcon image, then set it to jLabel and add jLabel to your frame.
  • Override the paintComponents() your frame to draw the image using the graphics in it. {Not sure about that}
  • Override the paintComponent() a panel or any other component to draw an image using Graphics in it, and then add this component to the frame.
+2
source

You can use shortcuts, as Sanjay says.

also using a layered panel that you can use as a background image.

+2
source

You can try to do it like this:

  • ImageIcon image = new ImageIcon(getClass().getResource("imageName.png"));
  • JLabel lblImage = new JLabel(image);

line 1 of the code will receive an image ensuring that the image is in the same folder in which you save your work.

0
source

Source: https://habr.com/ru/post/1386648/


All Articles