控制器:
package sample;
import javafx.event.*;
import javafx.fxml.FXML;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.scene.control.TextField;
public class Controller {
@FXML TextFlow textFlow;
@FXML TextField textField = new TextField();
public void click(ActionEvent event){
System.out.print(textField.getText());
Text text = new Text("Text from textField");
textFlow.getChildren().add(text);
}
}
我希望能够从textField获取文本并将其打印到textFlow。我是Java的新手,我做了一些搜索。我该怎么做?
答案 0 :(得分:-1)
为某个组件创建ActionListener并执行:
String text = textField.getText();
和
textFlow.getChildren().addAll(text);