FXMLLoader how to access the components by FXID?

前端 未结 2 1686
盖世英雄少女心
盖世英雄少女心 2020-12-05 16:08

I\'m trying to figure out how to work with JavaFx. I built the application interface in Scene Builder. But I can not get access to the component, since all loaded into the P

2条回答
  •  死守一世寂寞
    2020-12-05 17:03

    FXMLLoader.getNamespace() can be used, this is a map of named components.

    FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
    Parent root = loader.load();
    TextField foo = (TextField)loader.getNamespace().get("exampleFxId");
    

提交回复
热议问题