Вот мой код fxml и код файла контроллера Java. Я пытаюсь получить текст из TEXTFIELD tf в событии handle, используя «String s = tf.getText(). ToString();» но он не выполняется.Получение текста из текстового поля java fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id = "aPane" prefHeight="268.0" prefWidth="379.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="sample.searchController">
<children>
<VBox layoutX="20.0" layoutY="36.0" prefHeight="232.0" prefWidth="333.0">
<children>
<HBox prefHeight="36.0" prefWidth="333.0">
<children>
<Label fx:id= "kw" text="Key Word : ">
<padding>
<Insets right="10.0" />
</padding>
</Label>
<TextField fx:id="tf" prefHeight="25.0" prefWidth="120.0" />
<Button fx:id="srch" mnemonicParsing="false" onAction="#handle" text="Search" >
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Button>
</children>
<padding>
<Insets left="6.0" top="6.0" />
</padding>
<VBox.margin>
<Insets />
</VBox.margin>
<opaqueInsets>
<Insets />
</opaqueInsets>
</HBox>
<TextArea fx:id="ta" prefHeight="174.0" prefWidth="282.0" />
</children>
</VBox>
</children>
</AnchorPane>
JAVA код контроллера:
public class searchController implements Initializable,EventHandler<ActionEvent> {
AnchorPane aPane = new AnchorPane();
Label kw = new Label();
public TextField tf;
Button srch = new Button();
TextArea ta = new TextArea();
//Text t;
String s = "priyam";
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
tf = new TextField();
}
@Override
public void handle(ActionEvent arg0) {
// TODO Auto-generated method stub
s=tf.getText().toString();
System.out.println(s);
}
}
спасибо большое –