[英]How to initialize a TextField and get the text into TextFlow in JavaFX
Controller: 控制器:
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);
}
}
I want to be able to get the text from the textField and print it to textFlow. 我希望能够从textField中获取文本并将其打印到textFlow。 I'm new to Java and I've done some searches.
我是Java新手,已经进行了一些搜索。 How do I do that?
我怎么做?
Create ActionListener for some component and do: 为某些组件创建ActionListener并执行以下操作:
String text = textField.getText();
and 和
textFlow.getChildren().addAll(text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.