将对象列表存储到FlowPane中

时间:2015-03-03 19:24:38

标签: javafx javafx-2 javafx-8

我有一个自定义对象,我想将其存储到FlowPane中。例如,我尝试创建自定义对象列表并将它们插入FlowPane但我失败了:

private final List<LivePerformanceChart> list = new ArrayList<>();
private final FlowPane flow = new FlowPane();
flow.getChildren().addAll(list);

我正在寻找一种方法将自定义图表对象存储到FlowPane中,并使用一个Sheduled Task更新图表值。我能想到的简单方法是迭代所有FlowPane子节点并使用公共Java方法更新图表值。

你能告诉我一些如何做到这一点的例子吗?

编辑: 我也试过这个:

这是我的自定义类:

public class LivePerformanceChart{......}

LivePerformanceChart zz = new LivePerformanceChart(); flow.getChildren()添加(ZZ);

我得到: 找不到合适的添加方法(LivePerformanceChart)

method Collection.add(Node) is not applicable
  (argument mismatch; LivePerformanceChart cannot be converted to Node)
method List.add(Node) is not applicable
  (argument mismatch; LivePerformanceChart cannot be converted to Node)

我可以尝试以这种方式迭代孩子:

for(int i=0; i<flow.getChildren().size(); i++){

                        Node obj = flow.getChildren().get(i);

                        if(obj instanceof LivePerformanceChart){


                        } 

                    }

我来了

incompatible types: Node cannot be converted to LivePerformanceChart

你能帮我解决问题吗?

1 个答案:

答案 0 :(得分:2)

我使用类似的技术将我的Label对象添加到flowpane列表中。这是我正在使用的示例代码 -

Flowpane fpmoduleContainer[app] = new FlowPane();
 ArrayList<Label> listlbs = new ArrayList<Label>(moduleList.size());
                    int i = 0;
                    for (ModuleAttribute mattribute : moduleList) {
                        listlbs.add(new Label());
                        listlbs.get(i).setText(mattribute.getModule_name());
                        i = i + 1;
                    }
                    fpmoduleContainer[app].getChildren().addAll(listlbs);