如何初始化TextField并将文本转换为JavaFX中的TextFlow

时间:2017-11-20 11:13:33

标签: java javafx

控制器:

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);
    }
}

enter image description here

我希望能够从textField获取文本并将其打印到textFlow。我是Java的新手,我做了一些搜索。我该怎么做?

1 个答案:

答案 0 :(得分:-1)

为某个组件创建ActionListener并执行:

String text = textField.getText(); 

textFlow.getChildren().addAll(text);