不能';t将侦听器添加到文本字段javafx

不能';t将侦听器添加到文本字段javafx,java,javafx,controller,listener,fxml,Java,Javafx,Controller,Listener,Fxml,我正在尝试将listener添加到控件中的textfield,但却没有这样做。在使用指定给该特定文本字段的fx:id时,我在控件中找不到textfield的任何选项 sample.fxml controller.java import java.io.FileNotFoundException; 导入java.net.URL; 导入java.util.ArrayList; 导入java.util.ResourceBundle; 导入javafx.beans.value.observeValu

我正在尝试将listener添加到控件中的textfield,但却没有这样做。在使用指定给该特定文本字段的fx:id时,我在控件中找不到textfield的任何选项

sample.fxml

controller.java
import java.io.FileNotFoundException;
导入java.net.URL;
导入java.util.ArrayList;
导入java.util.ResourceBundle;
导入javafx.beans.value.observeValue;
导入javafx.event.ActionEvent;
导入javafx.fxml.fxml;
导入javafx.fxml.Initializable;
导入javafx.scene.control.Button;
导入javafx.scene.control.RadioButton;
导入javafx.scene.control.TextField;
导入javafx.scene.control.ToggleGroup;
导入javafx.scene.layout.ancorpane;
公共类控制器实现可初始化{
@FXML
私有文本字段msg_tb;
@FXML
私有文本字段n_msg_tb;
@FXML
专用按钮复位;
@FXML
私人无线电按钮;
@FXML
私人交换组1;
@FXML
私人无线按钮dr;
@FXML
私人锚烷电子书;
@FXML
私人锚烷dbox;
@FXML
公共文本字段e_key_tb;
@FXML
私有文本字段d_key_tb;
@FXML
无效d_c(动作事件){
}
@FXML
无效d_c_密钥_tb(ActionEvent事件){
}
@FXML
作废dr_操作(ActionEvent事件){
setVisible(true);
dbox.setDisable(false);
ebox.setVisible(假);
ebox.setDisable(true);
}
@FXML
无效e_at(ActionEvent事件){
}
@FXML
无效e_c(动作事件){
}
@FXML
无效e_c_密钥_tb(ActionEvent事件){
}
@FXML
无效e_nl(动作事件){
}
@FXML
作废er_动作(动作事件){
ebox.setVisible(true);
ebox.setDisable(false);
dbox.setVisible(false);
setDisable(true);
}
@FXML
无效重置(ActionEvent事件){
}
@凌驾
公共void初始化(URL位置、ResourceBundle资源){
ArrayList mkey=新的ArrayList();
试一试{
莫尔斯负荷(mkey);
}catch(filenotfounde异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
公共文本字段getMsg_tb(){
返回msg_tb;
}
公共无效设置消息\u tb(文本字段消息\u tb){
this.msg_tb=msg_tb;
}
公共文本字段getN_msg_tb(){
返回n_msg_tb;
}
公共无效设置n_msg_tb(文本字段n_msg_tb){
this.n_msg_tb=n_msg_tb;
}
公共按钮getReset_b(){
返回复位b;
}
公共无效设置重置(按钮重置){
this.reset_b=reset_b;
}
公共单选按钮getEr(){
回程电流互感器;
}
公共无效设置器(单选按钮设置器){
这个,呃,呃,;
}
公共切换组getGroup1(){
返回组1;
}
公共无效设置组1(切换组组1){
this.group1=group1;
}
公共单选按钮getDr(){
返回dr;
}
公共无效setDr(单选按钮dr){
this.dr=dr;
}
公共主播getEbox(){
返回电子书;
}
公共无效电子邮箱(AnchorPane电子邮箱){
this.ebox=ebox;
}
公共主播getDbox(){
返回dbox;
}
公共无效设置框(锚烷数据库框){
this.dbox=dbox;
}
公共文本字段getE_key_tb(){
返回e_key_tb;
}
公共无效设置密钥tb(文本字段密钥tb){
这是e_key_tb=e_key_tb;
}
公共文本字段getD_key_tb(){
返回d_key_tb;
}
公共无效设置d_key_tb(文本字段d_key_tb){
this.d_key_tb=d_key_tb;
}
e_key_tb.textProperty().addListener((ob
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.effect.Reflection?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="294.0" prefWidth="883.0" style="-fx-background-color: #000000;" stylesheets="@style.css" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controler">
   <children>
      <Label layoutX="28.0" layoutY="55.0" text="Enter Text : " AnchorPane.leftAnchor="28.0">
         <font>
            <Font size="15.0" />
         </font>
      </Label>
      <TextField fx:id="msg_tb" alignment="CENTER" layoutX="117.0" layoutY="52.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="@style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
      <TextField fx:id="n_msg_tb" alignment="CENTER" layoutX="117.0" layoutY="93.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="@style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
      <Button fx:id="reset_b" alignment="CENTER" layoutX="602.0" layoutY="171.0" mnemonicParsing="false" onAction="#reset" style="-fx-text-fill: #FFFFFF; -fx-background-radius: 20;" stylesheets="@style.css" text="RESET" AnchorPane.rightAnchor="161.0">
         <font>
            <Font name="Calibri Bold" size="31.0" />
         </font>
         <effect>
            <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
         </effect>
      </Button>
      <VBox layoutX="495.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="@style.css" AnchorPane.rightAnchor="221.0">
         <children>
            <RadioButton fx:id="er" mnemonicParsing="false" onAction="#er_action" prefHeight="17.0" prefWidth="92.0" stylesheets="@application.css" text="ENCRIPTION" textFill="#797979">
               <toggleGroup>
                  <ToggleGroup fx:id="group1" />
               </toggleGroup>
            </RadioButton>
            <AnchorPane fx:id="ebox" prefHeight="150.0" prefWidth="167.0">
               <children>
                  <Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="@application.css" text="NUMBER LETTER">
                     <graphic>
                        <Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_nl" prefHeight="15.0" prefWidth="15.0" text="*">
                           <effect>
                              <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                           </effect>
                        </Button>
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="@application.css" text="AT-BASH">
                     <graphic>
                        <Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_at" prefHeight="15.0" prefWidth="15.0" text="Button">
                           <effect>
                              <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                           </effect>
                        </Button>
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="@style.css" text="CEASER">
                     <graphic>
                        <TextField fx:id="e_key_tb" onAction="#e_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="@style.css" />
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Button alignment="CENTER" disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="@application.css" text="CEASER" textAlignment="CENTER">
                     <font>
                        <Font name="System Italic" size="8.0" />
                     </font>
                     <effect>
                        <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                     </effect>
                  </Button>
               </children>
            </AnchorPane>
         </children>
      </VBox>
      <VBox layoutX="662.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="@style.css" AnchorPane.rightAnchor="54.0">
         <children>
            <RadioButton fx:id="dr" mnemonicParsing="false" onAction="#dr_action" prefHeight="17.0" prefWidth="98.0" stylesheets="@application.css" text="DECRIPTION" textFill="#797979" toggleGroup="$group1" />
            <AnchorPane fx:id="dbox" prefHeight="150.0" prefWidth="167.0" visible="false">
               <children>
                  <Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="@application.css" text="NUMBER LETTER">
                     <graphic>
                        <Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="*">
                           <effect>
                              <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                           </effect>
                        </Button>
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="@application.css" text="AT-BASH">
                     <graphic>
                        <Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="Button">
                           <effect>
                              <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                           </effect>
                        </Button>
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="@style.css" text="CEASER">
                     <graphic>
                        <TextField fx:id="d_key_tb" onAction="#d_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="@style.css" />
                     </graphic>
                     <padding>
                        <Insets top="15.0" />
                     </padding>
                  </Label>
                  <Button disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#d_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="@application.css" text="CEASER" textAlignment="CENTER">
                     <font>
                        <Font name="System Italic" size="8.0" />
                     </font>
                     <effect>
                        <Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
                     </effect>
                  </Button>
               </children>
            </AnchorPane>
         </children>
      </VBox>
   </children>
</fx:root>
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;

public class controler implements Initializable {

    @FXML
    private TextField msg_tb;

    @FXML
    private TextField n_msg_tb;

    @FXML
    private Button reset_b;

    @FXML
    private RadioButton er;

    @FXML
    private ToggleGroup group1;

    @FXML
    private RadioButton dr;

    @FXML
    private AnchorPane ebox;

    @FXML
    private AnchorPane dbox;

    @FXML
    public TextField e_key_tb;




    @FXML
    private TextField d_key_tb;

    @FXML
    void d_c(ActionEvent event) {

    }

    @FXML
    void d_c_key_tb(ActionEvent event) {

    }

    @FXML
    void dr_action(ActionEvent event) {
        dbox.setVisible(true);
        dbox.setDisable(false);
        ebox.setVisible(false);
        ebox.setDisable(true);
    }

    @FXML
    void e_at(ActionEvent event) {

    }

    @FXML
    void e_c(ActionEvent event) {

    }

    @FXML
    void e_c_key_tb(ActionEvent event) {

    }

    @FXML
    void e_nl(ActionEvent event) {

    }

    @FXML
    void er_action(ActionEvent event) {

        ebox.setVisible(true);
        ebox.setDisable(false);
        dbox.setVisible(false);
        dbox.setDisable(true);


    }

    @FXML
    void reset(ActionEvent event) {

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        ArrayList<morse> mkey = new ArrayList<>();
        try {
            morse.load(mkey);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public TextField getMsg_tb() {
        return msg_tb;
    }

    public void setMsg_tb(TextField msg_tb) {
        this.msg_tb = msg_tb;
    }

    public TextField getN_msg_tb() {
        return n_msg_tb;
    }

    public void setN_msg_tb(TextField n_msg_tb) {
        this.n_msg_tb = n_msg_tb;
    }

    public Button getReset_b() {
        return reset_b;
    }

    public void setReset_b(Button reset_b) {
        this.reset_b = reset_b;
    }

    public RadioButton getEr() {
        return er;
    }

    public void setEr(RadioButton er) {
        this.er = er;
    }

    public ToggleGroup getGroup1() {
        return group1;
    }

    public void setGroup1(ToggleGroup group1) {
        this.group1 = group1;
    }

    public RadioButton getDr() {
        return dr;
    }

    public void setDr(RadioButton dr) {
        this.dr = dr;
    }

    public AnchorPane getEbox() {
        return ebox;
    }

    public void setEbox(AnchorPane ebox) {
        this.ebox = ebox;
    }

    public AnchorPane getDbox() {
        return dbox;
    }

    public void setDbox(AnchorPane dbox) {
        this.dbox = dbox;
    }

    public TextField getE_key_tb() {
        return e_key_tb;
    }

    public void setE_key_tb(TextField e_key_tb) {
        this.e_key_tb = e_key_tb;
    }

    public TextField getD_key_tb() {
        return d_key_tb;
    }

    public void setD_key_tb(TextField d_key_tb) {
        this.d_key_tb = d_key_tb;
    }






     e_key_tb.textProperty().addListener((obs, oldText, newText) -> {
            System.out.println("Text changed from "+ oldText +" to "+newText);

        });


    }
}
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>

<HBox prefHeight="75.0" prefWidth="150.0" alignment="CENTER" 
xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1"  fx:controller="tests.Controler">
   <children>
       <TextField fx:id="msg_tb" prefHeight="25.0" prefWidth="100.0" style="-fx-background-radius: 10;" />
   </children>
</HBox>  
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;

public class Controler implements Initializable {

    @FXML
    private TextField msg_tb;

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        msg_tb.textProperty().addListener((obs, oldText, newText) -> {
            System.out.println("Text changed from "+ oldText +" to "+newText);
        });
    }
}
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class FxmlMain extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Pane root = FXMLLoader.load(getClass().getResource("xml/FxmlMain.fxml"));
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    public static void main(String[] args) { launch(args);}
}