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