I am trying to represent a TreeCell like this:
I have tried reading up on cell factories and I know I have to use this functionality. But how can I set the graphics to be like this for all the TreeCells? The image is stored as an HBox in an .fxml-file.
Thank you so much :)
P.S. Not necessarily looking for code in the answer here, more of a general explanation as to how to do this or why it doesn't work.
This is the code I have tried. The fxml file is in the same folder as the file.
This is the error code I get:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Location is required.
@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);
}
}