Share on Google+Share on Google+

Java Image On JFrame Title

Advertisement
In this section, you will learn how to set an image on JFrame title Using Java Language.

How to set Image On JFrame

In this section, you will learn how to set an image on JFrame title using Java program. For this, we have created an object of JFrame class. Then, we have used Toolkit.getDefaultToolkit().getImage() that will load the specified image and the method setIconImage() of JFrame class have allowed  the image to be displayed on the JFrame title.

Here is the code:

import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JFrame;

public class ImageOnFrame {
  public static void main(String[] unused) {
    JFrame f = new JFrame("Frame");
    Image im = Toolkit.getDefaultToolkit().getImage("C:\\node.jpg");
  f.add(new JLabel("Hello World"));
    f.setIconImage(im);
    f.setSize(100100);
    f.setLocation(500500);
    f.setVisible(true);
  }
}

Advertisements

Posted on: October 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.