定製TreeCells我想代表TreeCell這樣的:使用電池工廠
http://i.imgur.com/wv00CEi.png
我試圖在細胞工廠讀書了,我知道我要使用此功能。但是我怎樣才能將圖形設置爲像所有TreeCell一樣?該圖像作爲HBox存儲在.fxml文件中。
非常感謝你:)
P.S.不一定在這裏找答案中的代碼,更多的是關於如何做到這一點或爲什麼不起作用的一般性解釋。
這是我試過的代碼。 fxml文件與文件位於同一個文件夾中。
這是錯誤代碼我得到:螺紋
例外「的JavaFX應用程序線程」顯示java.lang.NullPointerException:需要位置。
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
try {
this.hBox = (HBox) FXMLLoader.load(getClass().getResource("/Views/TreeCell.fxml"));
} catch (IOException e) {
System.out.println("This didn't work");
e.printStackTrace();
}
if (item != null) {
setGraphic(this.hBox);
} else {
setGraphic(null);
}
}
你能告訴你已經嘗試的代碼?很難說沒有看到它,爲什麼它不起作用。 – 2014-11-04 15:34:15
編輯顯示我正在嘗試的代碼片段。 – AnagramOfJoans 2014-11-04 15:54:59