zoukankan      html  css  js  c++  java
  • 在控制器中如何对fxml的控件初始化

    如果在控制器中实现Initializable这个接口,并重iInitializable这个方法

    对于一个fxml文件来说它首先执行控制器的构造函数,这个时候它是无法对@FXML修饰的方法进行访问的,然后执行@FXML修饰的方法,最后执行initializable方法,我们可以在initializable方法中

    对fxml文件的控件进行初始化

     1 //package application;
     2 package application;
     3 
     4 import java.io.File;
     5 import java.net.URL;
     6 import java.util.ResourceBundle;
     7 
     8 import com.sun.prism.paint.Color;
     9 
    10 import javafx.event.ActionEvent;
    11 import javafx.fxml.FXML;
    12 
    13 import javafx.scene.text.Text;
    14 import javafx.fxml.Initializable;
    15 public class MyController implements Initializable {
    16 @FXML
    17     private Label textOne;
    18     public MyController() {
    19         System.out.print("one method");
    20     }
    21     @Override
    22     public void initialize(URL location, ResourceBundle resources) {
    23         // TODO Auto-generated method stub
    24         textOne.setText("qwe");
    25         }
    26 }

    fxml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.control.Label?>
    <AnchorPane fx:controller="application.MyController"
        maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
        minWidth="-Infinity" prefHeight="717.0" prefWidth="824.0"
        xmlns="http://javafx.com/javafx/8.0.171"
        xmlns:fx="http://javafx.com/fxml">
        <children>
            <Label alignment="TOP_CENTER" layoutX="60.0" layoutY="139.0"
                text="电影排行" />
        </children>
    </AnchorPane>
  • 相关阅读:
    EnumMap实现类
    java enum
    openssl生成RSA公钥和私钥对
    rsa 公钥 私钥
    eclispe 通过git向码云上传
    eclipse git 报 git: 401 Unauthorized
    HttpClient 超时时间
    HttpClient 4 和 HttpClient 3 超时
    Java RSA 生成公钥 私钥
    万能适配器
  • 原文地址:https://www.cnblogs.com/moomcake/p/11875530.html
Copyright © 2011-2022 走看看