Swing image class

Discussion in 'Java' started by bob smith, Jan 18, 2013.

  1. bob smith

    bob smith Guest

    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.
     
    bob smith, Jan 18, 2013
    #1
    1. Advertising

  2. bob smith

    FredK Guest

    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?
     
    FredK, Jan 18, 2013
    #2
    1. Advertising

  3. In article <>,
    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.


    Unable to reproduce:

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

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

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Jan 18, 2013
    #3
  4. 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
     
    Knute Johnson, Jan 18, 2013
    #4
  5. bob smith

    Daniel Pitts Guest

    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.
     
    Daniel Pitts, Jan 18, 2013
    #5
  6. bob smith

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Jan 18, 2013
    #6
  7. bob smith

    Roedy Green Guest

    On Fri, 18 Jan 2013 07:20:15 -0800 (PST), bob smith
    <> 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/mindprod/common11/ImageViewer.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
     
    Roedy Green, Jan 19, 2013
    #7
  8. bob smith

    Lew Guest

    Roedy Green wrote:
    > Perhaps they considered it too simple. Here is one
    > https://wush.net/svn/mindprod/com/mindprod/common11/ImageViewer.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
     
    Lew, Jan 19, 2013
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    501
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    674
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,771
    lizard
    Jan 30, 2006
  4. S.T
    Replies:
    2
    Views:
    582
  5. Knute Johnson

    Swing is dead! Long live Swing.

    Knute Johnson, Feb 16, 2012, in forum: Java
    Replies:
    32
    Views:
    3,771
    Daniel Pitts
    Feb 29, 2012
Loading...

Share This Page