Reputation: 213
I've tried the code below.
try {
this.setIconImage(ImageIO.read(new File("/resources/dbs.ico")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.getMessage());
System.exit(0);
}
Alsow I've tried the code given below.
yourFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(Filepath)));
Also I've tried the code given below.
URL iconURL = getClass().getResource("/some/package/favicon.png");
ImageIcon icon = new ImageIcon(iconURL);
frame.setIconImage(icon.getImage());
But none of all these solution is working. The directory structure is :
/pro_root/com/girishpro/multirecharge/resources/dbs.ico
Also I've tried below.
/pro_root/resources/dbs.ico
The dbs.ico is the image which I want to set as Icon for JFrame. Please help me for solving this problem.
Upvotes: 1
Views: 1520
Reputation: 213
as the answer is given above. In java, .ico is partially or not supported. So to everyone who is finding correct solution, please ensure that for icon, you are not using .ico file for icon. Thanks to Andrew Thompson
Upvotes: 1
Reputation: 168845
Use ImageIO.getReaderFileSuffixes()
for an array of file types that the Java run-time can read. It might appear like this (actual example for this machine right now):
type: bmp
type: jpg
type: wbmp
type: jpeg
type: png
type: gif
Nope. No ico
type.
Upvotes: 4
Reputation: 1
Try the code below and verify the path of the image according to the class of the JFrame.
try {
SetIconImage(ImageIO.read(getClass().getResource("/images/image.ico")));
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0
Reputation: 57421
According to your structure the dbs.ico is placed in the root together with packages of your classes.
So the code should work
ImageIO.read(getClass().getResourceAsStream("/dbs.ico"))
Upvotes: 0