Setting stylesheets declaratively in FXML

后端 未结 3 720
余生分开走
余生分开走 2021-02-18 20:37

In HTML we are used to niceties of being able to set stylesheets programmatically like


But the examples of

3条回答
  •  独厮守ぢ
    2021-02-18 21:06

    If you are going to use fxml with JavaFX you should take some time to download and use SceneBuilder. Once you do that use of css style sheets becomes simple. Of course, use NetBeans since with SceneBuilder running, opening the prebuilt dxml file in the NetBeans dxml boilerplate application causes it to be automatically open for editing in SceneBuilder. Once you have ripped out all the StackPlane, button and label and put in the controls and containers you really want, just add the style sheet directly to SceneBuilder. In the main menu, under Preview, there is a menu selection for CSS style sheets. Selecting it brings up a submenu which will let you load a style sheet file.

    Once the file is loaded, the controls will show to be skinned according to the rules in the style sheet they won't show that skin until you select each one in the properties section of SceneBuilder and declare that style sheet as applied to that control. Then the style will show when the application runs.

提交回复
热议问题