Is it possible to set a JavaFX static property in CSS?

夙愿已清 提交于 2019-12-31 01:50:25

问题


Sample FXML with the BorderPanel.alignment "static property":

<BorderPane>
  <top>
    <Label text="My Label" BorderPanel.alignment="CENTER"/>           
  </top>
</BorderPane>

The CSS-supported version:

<BorderPane stylesheets="Style.css">
   <top>
     <Label text="My Label" styleClass="labelClass"/>           
   </top>
</BorderPane>

Style.css would be:

.labelClass
 {
   -fx-borderpanel-alignement: center
 }

回答1:


For JavaFX versions 2.0 to 2.2 => no you cannot set the static layout properties via css.

You can create a feature request in the JavaFX jira to ask this functionality be implemented in a future JavaFX version.




回答2:


You can apply it programatically. For example if you want to center all the widgets of a GridPane, instead of writing GridPane.halignment="CENTER" in the XML declaration of each widget, you can do this in Java :

for(Node node : gridPane.getChildren())
{
    GridPane.setHalignment(node, HPos.CENTER);
}

Unfortunately I don't think you can factorize layouts as in Android :(



来源:https://stackoverflow.com/questions/11691931/is-it-possible-to-set-a-javafx-static-property-in-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!