Hi there, I'm new to JBuilder 9 and have had school experience with using JAVA. I am trying to display a .jpg file. I already have loaded it with: ------------------------- Image image = null; // Read from a file File file = new File("C:\\FILES\\martian_girlfriend.jpg"); image = ImageIO.read(file); -------------------------- How do I now display the loaded image? I already have gotten it to work and load in a separate frame, but I am looking to load it into another SWING component like JScollPane or other. This might not be possible since I'm such a Newbie and do not know the full power of Swing. So please send help. Thanks, Melanie.
If you are using Swing, just load it in an ImageIcon and put the icon on a JLabel.
If you're using a JPEG, GIF, or PNG image, you can also just send the filename directly to the ImageIcon constructor. Once you've put the icon on the JLabel, you can put the JLabel in a JScrollPane if you wanted to.
If you're wanting to display an image in AWT, you'll need to subclass a component and override the paint() method. If you need to do this there are plenty of examples... just search the forum.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Thanks Nate. Late last night I also got it working but thanks for the scroll tip. For other newbies, here's the code: This will on pressing a button, popup an image in the JLabel field and also pop an image up in a frame.