JavaFx在GridPane中获取文本字段值

问题描述 投票:-1回答:1

我正在使用GridPane来显示用户输入的结果。

在GridPane中,它有两列,分别是标签的VBox和值的VBox。标签和值为文本。

这是我创建GridPane的方式。

   Text textLabel = new Text(label);
   Text textValue = new Text(value);

   VBox labelVbox = new VBox(textLabel);
   VBox valueVbox = new VBox(textValue);

   gridPane.add(labelVbox, 0, rowIndex);
   gridPane.add(valueVbox, 1, rowIndex);

那些GridPane包含两列多于一行。如何获取每一行的textValue的Text值?

java javafx gridpane
1个回答
-1
投票

您听说过javadoc吗?

GridPane的父类具有方法getChildren(),该方法返回包含的节点的列表。

遍历列表,并为每个孩子得到其文本。

根据您发布的代码,您只希望第1列(一)中的节点,因此可以使用方法getChildren()仅过滤出与您相关的子节点。类似于:

getColumnIndex()
© www.soinside.com 2019 - 2024. All rights reserved.