Method One:
If you've ever used the Toolkit class, it's a very simple thing to do:
Toolkit Tk=toolkit.getdefaulttoolkit ()
Image image=tk.createimage ("Image.gif"); /*image.gif is your icon */
This.seticonimage (image);
It's that simple, look, it's become your own icon. Toolkit is a very useful class, providing a lot of changes to the default behavior of the window, the following casually mention, how to change the default mouse icon to your own icon:
Toolkit Tk=toolkit.getdefaulttoolkit ();
Image img=tk.getimage ("Mouse.gif"); /*mouse.gif is your icon */
Cursor Cu=tk.createcustomcursor (img,new Point (10,10), "stick");
This.setcursor (CU);
Method Two:
Use the ImageIcon class and the Seticonimage method.
Import javax.swing.*;
public Class AA extends JFrame {
String image = new String ("Face.gif"); Create a string to save the path of the icon to use, refer to other documentation for the path to Java
ImageIcon test = new ImageIcon (image); Create an ImageIcon class that produces the image data required by the Seticonimage () method
public aa () {
super ("Ways to show the icon of the custom title bar");
This.seticonimage (Test.getimage ()); Set the icon for the title bar to Face.gif
this.setdefaultcloseoperation (jframe.exit_on_ CLOSE);
this.show ();
//this.settitle ("Sdfsdf");
this.setsize (400,200);
}
public static void Main (string[] args) {
AA Jicon = new AA ();
}
}
Simplified statements:
Import javax.swing.*;
public Class AA extends JFrame {
ImageIcon test = new ImageIcon (new String (face.gif));//First sentence
Public aa () {
Super ("How to show the icon of a custom title bar");
This.seticonimage (Test.getimage ()); Second sentence
This.setsize (400,200);
This.show ();
}
public static void Main (string[] args) {
AA Jicon = new AA ();
}
}
How to change the Java Application title bar default icon