取得GridPane內的TextField內容
Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<Pane prefHeight="600.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.221" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.var.client.netty.Controller">
<children>
<SplitPane dividerPositions="0.5" layoutX="220.0" layoutY="100.0" orientation="VERTICAL" prefHeight="500.0" prefWidth="781.0">
<items>
<GridPane fx:id="protoTextFieldGrid" hgap="10.0" maxHeight="Infinity" maxWidth="Infinity" vgap="5">
</GridPane>
</items>
</SplitPane>
</children>
</Pane>
Controller.java
package com.var.client.netty;
public class Controller {
@FXML
GridPane protoTextFieldGrid;
private void sendProtoMsgButton(int key) throws InterruptedException {
sendMsg("Click Send Button", "Click");
Map<String, String> data = new HashMap<>();
for (Node node :protoTextFieldGrid.getChildren()) {
//如果 node 為 TextField
if (node instanceof TextField) {
TextField tx = (TextField)node;
//為空則不印
if (tx.getText().equals(""))
continue;
System.out.println(data.put(tx.getId(), tx.getText()));
}
}
}
}