2013-08-20 58 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

相關問題