This content has been marked as final.
Show 3 replies
-
1. Re: Put an Image into a JPanel
gimbal2 Jan 8, 2013 10:41 PM (in response to 983618)980615 wrote:
That's not a question nor a problem description. Did you try it? What happened? What was wrong about it?
I don't know if I am doing it well, this is my code:
Note that you generally only have to call setVisible() on the frame, not on the components in it.
And PS: please use \tags when posting code.
-
2. Re: Put an Image into a JPanel
983618 Jan 9, 2013 12:08 AM (in response to gimbal2)My question is in the title. The unique things that is not happening is: the image is not appearing in the window. And I don't know if I am doing something bad.
If I only use: this.add(Img); -> The image appear, but no in the JPanel. I want to insert the image in the JPanel and show it.
Ok, I delete the other setVisible, and I only let the "this.setVisible".
The problem is still the same. -
3. Re: Put an Image into a JPanel
980759 Jan 9, 2013 6:29 AM (in response to 983618)try the below and remove Runnable interface and check your image pathBufferedImage picture = null; try { picture = ImageIO.read(new File("/untitled.png")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JLabel picLabel = new JLabel(new ImageIcon( picture )); add(picLabel); setBounds(100, 100, 640, 480); setVisible(true);