如何更新每个节点中具有自定义组件的 JavaFX 中的 anchorPane?

How to update the anchorPane in JavaFX having custom components in each node?

我有一个 AnchorPane。它将保存自定义 class summaryData 的对象。

汇总数据class如下

public summaryData (double rectX, double rectY, double width, double height) {
    rect = new Rectangle(rectX,rectY,width,height);
    rect.setStroke(javafx.scene.paint.Color.GRAY);
    rect.setFill(javafx.scene.paint.Color.TRANSPARENT);

    text  = new Text();

    text.setFont(Font.font(ChartFontUtil.getAverageFont().getFamily(),FontWeight.NORMAL,11));       

    text.setY(rectY+((rect.getHeight() + text.getFont().getSize())/2)-1);       
    text.setSmooth(true);
    getChildren().add(rect);
    getChildren().add(text);
}

现在 class 的对象通过下面的语句

添加到 AnchorPane 中
anchorPANE.getChildren().add(rectGroup);

其中 rectGroup 是 class summaryData 的一个对象。

现在我想更改此矩形上的文本集。所以我必须执行 setText()。 但是在更新的情况下我如何到达这个组件? 我的意思是我的锚窗格的所有节点如下所示

javafx.collections.ObservableList<Node> allRectGroups = anchorPANE.getChildren();

现在,是否有任何方法可以通过 NODE

引用此 rectGroup 对象的子对象
for(Node node : allRectGroups)
{
    // can this node will have any access to the object of class summaryData ?
}

您需要将节点向下转换为 SummaryCountRect 试试这个:

for(Node node : allRectGroups)
   {
     SummaryCountRect data = (SummaryCountRect) node ;
   }