How to change the Java Application title bar default icon

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.