JavaFx changes the icon of the title bar of the stage

Source: Internet
Author: User

Originally from: http://stackoverflow.com/questions/10275841/ how-to-change-the-icon-on-the-title-bar-of-a-stage-in-java-fx-2-0-of-my-applicat/15206407#15206407


Import Javafx.application.application;import Javafx.scene.scene;import Javafx.scene.layout.stackpane;import Javafx.scene.image.image;import Javafx.stage.stage;public class Stackoverflowicon extends application{    @ Override public    void Start (stage stage)    {        Stackpane root = new Stackpane ();        Scene scene = new Scene (root, +);        Set icon        stage.geticons (). Add (New Image ("/path/to/stackoverflow.jpg"));        Set title        stage.settitle ("wow!! StackOverflow Icon ");        Stage.setscene (scene);        Stage.show ();    }    /**     * @param args the command line arguments     *    /public static void main (string[] args)    {        launch (args);}    }

Run:


JavaFX 8 Upgrade


The above code still works and there is no need to modify it.  java 1.8 (1.8.0_31) environment for testing, testing. The path supports either local or remote.

stage.getIcons().add(new Image("/path/to/javaicon.png"));

Or

stage.getIcons().add(new Image("https://example.com/javaicon.png"));

I hope it helps you.



--------------------------------------------------------------------------------------------------------------- ------------------------------

You can also load images from within the classpath like this:


new Image(XYZ.class.getResourceAsStream("/xyz.png"))

XYZ is the class name (or the class name of the class where you are loading the picture) Xyz.png is your picture name. Put it in your classpath path or inside the jar package.

If your icon and class are placed in the same package, you can omit/






JavaFx changes the icon of the title bar of the stage

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.