2016-07-29 29 views
0

當嘗試使用下面的代碼,一個異常java.lang.UnsupportedOperationException發生:的getChildren方法是從類ScrollPane中失蹤的JavaFX

ScrollPane scrollPaneIdFx = new ScrollPane(); 
ImageView imageViewIdFx = new ImageView(); 
scrollPaneIdFx.getChildrenUnmodifiable().add(imageViewIdFx); 

,如果嘗試使用下面的代碼,然後的getChildren是不可見的,由於保護說明

ScrollPane scrollPaneIdFx = new ScrollPane(); 
ImageView imageViewIdFx = new ImageView(); 
scrollPaneIdFx.getChildren().add(imageViewIdFx); 

有人可以建議,如何添加到ScrollPane兒童?

回答

3

一個ScrollPane存儲其獨生子女在contentProperty

用作此ScrollPane的內容的節點。

因此校正的代碼是:

scrollPaneIdFx.setContent(imageViewIdFx); 

在你情況下想多個Node 4S店在ScrollPane應該被設置爲所述容器中的一個(Parent對象)contentPropertyNode小號應該被添加到這個容器中。

1

只有一個「孩子」,你應該添加到ScrollPanecontent。如果您想要一個包含多個NodeScrollPane,請將它們添加到合適的Parent(例如Pane),並將此Parent作爲ScrollPane的內容。

VBox content = new VBox(); 
content.getChildren().add(child1); 
content.getChildren().add(child2); 
... 
scrollPane.setContent(content); 
相關問題