JavaFX (ii) custom window title bar

Source: Internet
Author: User

Problem Scenario:

PC Client Login Interface Imitation QQ, the top display picture, the bottom display input box and login button. The default window for JavaFX does not meet the requirements.

Ideas:

Hides the default title bar of the window, uses the Create label object, uses the CSS to replace the button picture with the Label object for layout, and acts as a button.

Realize:

Code snippet:

Stage.initstyle (stagestyle.transparent);//hide default title bar

Code snippet:

Label close = new label ();
Close.settooltip (New Tooltip ("Off"));
Close.setprefwidth (33);
Close.setprefheight (26);
Close.setid ("Winclose");//winclose CSS style ID
Close.setonmouseclicked (Shutdown event);//define the event handler yourself here

CSS Code snippet:

#winClose {
-fx-cursor:hand;
}

#winClose {
-fx-background-image:url ("/com/bb/winclose_0.png");
-fx-background-repeat:no-repeat;
}

#winClose: hover {
-fx-background-image:url ("/com/bb/winclose_1.png");
}

#winClose:p ressed {
-fx-background-image:url ("/com/bb/winclose_2.png");
}

JavaFX has many layout-managed objects that make it easy to lay out components. The author uses the Anchorpane object in the project.

JavaFX (ii) custom window title bar

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.