I have a GridView displaying custom GridCell that I have created using FXML. I want this GridCells to be selectable and I need to listen to selection changes.
So far, I have tried the solutions provided here How to implement selection of Nodes in JavaFX without luck
//Here is the code of My Custom GridCell
public class IconGridCell extends GridCell<IconItem> implements SelectableGridCell{
@FXML
public AnchorPane gridCell;
@FXML
public FontIcon fontIcon;
private FXMLLoader mLLoader;
@Override
protected void updateItem(IconItem iconItem, boolean empty) {
super.updateItem(iconItem, empty);
if (empty || iconItem == null) {
setText(null);
setGraphic(null);
} else {
if (mLLoader == null) {
mLLoader = new FXMLLoader(getClass().getResource("/cell.fxml"));
mLLoader.setController(this);
try {
mLLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
}
fontIcon.setIconLiteral(iconItem.getIcon().getIconLiteral());
setText(null);
setGraphic(gridCell);
}
}
I want to be able to listen the selection changes so that I can update the UI accordingly