FXML中的JavaFX .getProperties()

时间:2015-09-02 18:08:31

标签: javafx fxml

如何将其移至FXML?

hBox.getProperties().put("key", "value");

1 个答案:

答案 0 :(得分:5)

你可以做到

<HBox>
    <properties key="value"/>
</HBox>

,如documentation

变化

<HBox>
    <properties>
        <key>
            <String fx:value="value"/>
        </key>
    </properties>
</HBox>
如果您想要的值是更复杂的对象,

可能很有用:

<HBox>
    <properties>
        <character>
            <String fx:value="Arthur Dent"/>
        </character>
        <actor>      
            <Actor firstName="Simon" lastName="Jones"/>
        </actor>
    <properties>
</HBox>

相当于

Actor actor = new Actor();
actor.setFirstName("Simon");
actor.setLastName("Jones");
HBox hbox = new HBox();
hbox.getProperties().put("character", "Arthur Dent");
hbox.getProperties().put("actor", actor);
相关问题