[英]How to initialize a TextField and get the text into TextFlow in 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);
}
}
我希望能夠從textField中獲取文本並將其打印到textFlow。 我是Java新手,已經進行了一些搜索。 我怎么做?
為某些組件創建ActionListener並執行以下操作:
String text = textField.getText();
和
textFlow.getChildren().addAll(text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.