The code below shows you how you can simply set an icon to your frame in Java.This icon is seen on the title bar and also on the task bar while the program is running.
The method below is used to set the icon on the frame
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
Here is code snippet showing you how to set the icon on your frame
import javax.swing.*;
import java.awt.*;
public class FrameIcon {
public static void main(String[] args) {
JFrame frame = new JFrame("Frame Icon");
frame.setIconImage(Toolkit.getDefaultToolkit()
.getImage("res/icon.jpg"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
}
the out put is as below with the icon on the taskbar and on the title bar
The method below is used to set the icon on the frame
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif"));
Here is code snippet showing you how to set the icon on your frame
import javax.swing.*;
import java.awt.*;
public class FrameIcon {
public static void main(String[] args) {
JFrame frame = new JFrame("Frame Icon");
frame.setIconImage(Toolkit.getDefaultToolkit()
.getImage("res/icon.jpg"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
}
the out put is as below with the icon on the taskbar and on the title bar
Icon on the taskbar
icon on the title bar
0 comments:
Post a Comment