Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Swing image class

Reply
Thread Tools

Swing image class

 
 
bob smith
Guest
Posts: n/a
 
      01-18-2013
Is there really no built-in Swing class that just displays an image?

This is very hard to believe, but it looks like it at first google.

 
Reply With Quote
 
 
 
 
FredK
Guest
Posts: n/a
 
      01-18-2013
On Friday, January 18, 2013 7:20:15 AM UTC-8, bob smith wrote:
> Is there really no built-in Swing class that just displays an image? This is very hard to believe, but it looks like it at first google.


What's wrong with using JLabel?
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      01-18-2013
In article <(E-Mail Removed)>,
bob smith <(E-Mail Removed)> wrote:

> Is there really no built-in Swing class that just displays an image?
>
> This is very hard to believe, but it looks like it at first google.


Unable to reproduce:

<http://www.google.com/search?q=Swing%20class%20that%20displays%20an%20im age>

First hit: <http://stackoverflow.com/q/299495/230513>.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      01-18-2013
On 1/18/2013 7:20 AM, bob smith wrote:
> Is there really no built-in Swing class that just displays an image?
>
> This is very hard to believe, but it looks like it at first google.
>


http://rabbitbrush.frazmtn.com/

Three methods for loading an image for display.

--

Knute Johnson
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      01-18-2013
On 1/18/13 7:20 AM, bob smith wrote:
> Is there really no built-in Swing class that just displays an image?
>
> This is very hard to believe, but it looks like it at first google.


JFrame mainFrame = new JFrame();
mainFrame.add(new JLabel(new ImageIcon(imageFile)));
mainFrame.pack();
mainFrame.setVisible(true);


Done.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      01-18-2013
On 1/18/2013 10:20 AM, bob smith wrote:
> Is there really no built-in Swing class that just displays an image?
>
> This is very hard to believe, but it looks like it at first google.


Google was not your friend today.



There are different ways of doing it.

JLabel lbl = new JLabel();
lbl.setIcon(new ImageIcon(location));
getContentPane().add(lbl);

is the simplest.

protected void paintComponent(Graphics g) {
super.paintComponent(g);
BufferedImage img = ImageIO.read(location);
g.drawImage(img, 0, 0, this);
}

gives you the option to play with AffineTransform.

Arne



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-19-2013
On Fri, 18 Jan 2013 07:20:15 -0800 (PST), bob smith
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>Is there really no built-in Swing class that just displays an image?
>
>This is very hard to believe, but it looks like it at first google.


Perhaps they considered it too simple. Here is one

https://wush.net/svn/mindprod/com/mi...ageViewer.java

You can download the whole package at
http://mindprod.com/products1.html#COMMON11


You can use a JLabel/ImageIcon combo to get that effect in Swing.

see http://mindprod.com/jgloss/imageicon.html
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-19-2013
Roedy Green wrote:
> Perhaps they considered it too simple. Here is one
> https://wush.net/svn/mindprod/com/mi...ageViewer.java


That is a pretty little piece of code with Javadocs, clean and spare design,
complete functionality without overstepping its purpose, and usefulness.

> You can download the whole package at
> http://mindprod.com/products1.html#COMMON11
>
> You can use a JLabel/ImageIcon combo to get that effect in Swing.
>
> see http://mindprod.com/jgloss/imageicon.html


--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing is dead! Long live Swing. Knute Johnson Java 32 02-29-2012 05:10 PM
Why not using javax.swing.event with swing? S.T Java 2 05-25-2007 12:10 AM
javax.swing.Popup, javax.swing.PopupFactory lizard Java 0 01-30-2006 09:34 PM
Swing Model Classes Updating Swing Components on a Thread Other Than AWT mkrause Java 0 05-06-2005 04:32 PM
Java 1.2 Swing vs. Java 1.5 Swing Big Daddy Java 2 04-16-2005 01:14 PM



Advertisments