In this section, you will learn how to set an image on JFrame title Using Java Language.
In this section, you will learn how to set an image on JFrame title Using Java Language.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(100, 100); f.setLocation(500, 500); f.setVisible(true); } } |