2013-08-20 32 views

回答

9

您可以从Scene对象的ID中查找任何节点。

例如:

Scene scene = source.getScene(); 
Node nodeToFind = scene.lookup("#nodeToFindId"); 

该ID是一个CSS选择(ID),或FX ID。它必须在没有'#'字符的节点上进行设置。当调用方法'lookup'时,'#'字符必须在ID之前,如上所示。

+0

嗯..我得到java.lang.NullPointerException。也许问题是我开始我的图表是这样的: gantChartStage = new RmsGantChart(); gantChartStage.initModality(Modality.NONE); RmsGantChart扩展阶段 gantChartStage.showAndWait(); – kingkong

+0

当您尝试查找“nodeToFindID”时,源节点是否显示在场景中? – Aaron

0

嗯,我知道你想避免,但仍是不坏,并做的工作:

Node node = youNode; 
while (node != null){ 
    node = node.getParent(); 
} 
Node parentNode = node; 

否则,如果你有机会到现场对象:

Node parentNode = scene.getRoot(); 
+0

if(node.getId()。等于(myd)返回while循环中的节点,然后确定。 – pdem

相关问题