Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Swing image class (http://www.velocityreviews.com/forums/t956659-swing-image-class.html)

bob smith 01-18-2013 03:20 PM

Swing image class
 
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.


FredK 01-18-2013 04:25 PM

Re: Swing image class
 
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?

John B. Matthews 01-18-2013 04:37 PM

Re: Swing image class
 
In article <3a854a9f-1fb5-4001-ab84-7d6fd7987069@googlegroups.com>,
bob smith <bob@coolfone.comze.com> 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>

Knute Johnson 01-18-2013 05:05 PM

Re: Swing image class
 
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

Daniel Pitts 01-18-2013 06:55 PM

Re: Swing image class
 
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.

Arne Vajh°j 01-18-2013 11:40 PM

Re: Swing image class
 
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




Roedy Green 01-19-2013 07:30 AM

Re: Swing image class
 
On Fri, 18 Jan 2013 07:20:15 -0800 (PST), bob smith
<bob@coolfone.comze.com> 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

Lew 01-19-2013 08:48 AM

Re: Swing image class
 
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


All times are GMT. The time now is 02:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.