【发布时间】:2018-09-29 18:00:49
【问题描述】:
我有这段代码来查找所有“id”名称,但我现在想使用这些名称从同一个 fxml 中获取文本。
@FXML
private void handleButtonAction(ActionEvent event) {
Node source = (Node) event.getSource();
Scene scene = source.getScene();
ObservableList<Node> stringArray = source.getParent().getChildrenUnmodifiable();
for (int index = 0; index < stringArray.size(); index++) {
if (stringArray.get(index).getId() != null) {
System.out.println(stringArray.get(index).getId());
}
}
}
【问题讨论】:
-
将
source.getParent()转换为Node并使用Node.lookup("")获取TextField再次转换为TextField并获取您的文本.. 记得将fx:id=添加到您的TextField@ 987654329@无需循环 -
get the text from the same fxml 对我来说不太明白,你是什么意思?
标签: javafx textfield actionevent