This discussion is archived
5 Replies Latest reply: Jan 17, 2013 7:15 AM by abillconsl RSS

Displaying an image using Java

User_Sep Newbie
Currently Being Moderated
Hi,

I am new to java, I need to show my company logo(image) in a window using java program. For eg, Just like an "About" option in all softwares.

If we click the "About" option, the details about the software will be shown. I need to do that for my business need. So, pls guide me.


-Arunkumar Kootharasan.
  • 1. Re: Displaying an image using Java
    Kayaman Guru
    Currently Being Moderated
    Using an ImageIcon is probably the easiest way.
  • 2. Re: Displaying an image using Java
    gimbal2 Guru
    Currently Being Moderated
    Is this for an existing application? If so, which technology was used to build it? Swing? JavaFX?

    I'll guess Swing, check out the very complete Swing tutorial for explanation and example programs from which you can copy/paste:

    http://docs.oracle.com/javase/tutorial/uiswing/

    http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html
  • 3. Re: Displaying an image using Java
    abillconsl Explorer
    Currently Being Moderated
    Assuming you have a JFrame, something like this should work well for you. I posted the code because you state that you are a beginner. You should research each of these classes and their respective methods as was already suggested, but I felt that having something to start to work with would be advantageous for you:
      // Note imageName, below, is a String that is the name of a gif/jpg file that exists in the same folder or in a jarfile with the class.
        Image image = Toolkit.getDefaultToolkit().getImage( getClass().getResource( imageName ) );
        JLabel label = new JLabel(new ImageIcon(image));
        JPanel panel = new JPanel();
        panel.add(label);
        add(panel);
    ~Bill
  • 4. Re: Displaying an image using Java
    gimbal2 Guru
    Currently Being Moderated
    abillconsl wrote:
    Assuming you have a JFrame, something like this should work well for you. I posted the code because you state that you are a beginner. You should research each of these classes and their respective methods as was already suggested, but I felt that having something to start to work with would be advantageous for you:
    // Note imageName, below, is a String that is the name of a gif/jpg file that exists in the same folder or in a jarfile with the class.
    Image image = Toolkit.getDefaultToolkit().getImage( getClass().getResource( imageName ) );
    JLabel label = new JLabel(new ImageIcon(image));
    JPanel panel = new JPanel();
    panel.add(label);
    add(panel);
    ~Bill
    Indeed, but the links I provided also lead to a ton of example programs. You don't have to make the effort you know.
  • 5. Re: Displaying an image using Java
    abillconsl Explorer
    Currently Being Moderated
    I didn't go to the links you posted, but know that you post good stuff, so I took it for granted that the links were useful. That's why I posted that the OP should go and have a look at them in order to understand the code I posted, and just generally to obtain the needed knowledge - however far the OP is willing to go in that direction.

    As you might be aware, I don't post here very often anymore. But I happen to have some time lately and like to try to help, and like to try to solve problems. Most often, by the time I get around to doing either of the above, someone has beaten me to it. Other times I have nothing to offer on the subject. However, when I think I can add something, as I said, I like to do so. It's no real effort, in the sense of it being a burden, on my part to do so.

    ~Bill

    Edited by: abillconsl on Jan 17, 2013 10:15 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points