Article View: borland.public.jbuilder.java.swing
Article #1261Re: Send help: JBuilder 9: display .jpg file with JBuilder using components.
From: John McGrath [TeamB]
Date: Wed, 03 Mar 2004 09:13
Date: Wed, 03 Mar 2004 09:13
34 lines
2039 bytes
2039 bytes
On 3/2/2004 at 3:51:23 PM, Melanie Miller wrote:
> 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?
The easiest way to display an image is using a JLabel. You could
certainly use the code above to load the image, but there is an easier
approach using the ImageIcon class:
Icon icon = new ImageIcon( "C:\\FILES\\martian_girlfriend.jpg" );
JLabel label = new JLabel( icon );
Note that this assumes that you want to load the image from a *file*.
If the image is a static part of your application, you will probably
want to store the image along with your code (typically in a jar file),
and then create the Icon using the ImageIcon(URL) constructor.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<4045a1d1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4044f413$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,5a2f575c0d58ef1d X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-03 01:22:18 PST From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: Send help: JBuilder 9: display .jpg file with JBuilder using components. Newsgroups: borland.public.jbuilder.java.swing References: <4044f413$1@newsgroups.borland.com> User-Agent: XanaNews/1.16.1.11 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 151.197.214.141 Message-ID: <4045a1d1@newsgroups.borland.com> Date: 3 Mar 2004 01:13:53 -0800 X-Trace: newsgroups.borland.com 1078305233 151.197.214.141 (3 Mar 2004 01:13:53 -0800) Lines: 34 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail