javafx UI控件的代码绑定

方法一:

基于注解的方法:
第一步,在fxml文件中, <GridPane fx:controller="包名.类名">,选择作为控制整个图形界面的控制器的类。
第二步,在你选择的控制器中,以@FXML Button button;的形式绑定UI控件,button是在FMXL文件中定义的Button id。

方法二

            Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
            // #hight 中,#是必须写的hight是你所要绑定的id
            TextField hight=(TextField)root.lookup("#hight");

在任意类中,以上述形式绑定UI控件。

猜你喜欢

转载自blog.csdn.net/jihezhixin/article/details/86071596