I am new to Java FXML. I am still learning how to use Scene Builder 2.0 and controller classes. I don't understand why this is returning null
@FXML
public void gridClick(MouseEvent e){
Node source = (Node)e.getSource() ;
Integer colIndex = grid.getColumnIndex(source);
Integer rowIndex = grid.getRowIndex(source);
System.out.println("Mouse entered cell ["+colIndex+","+rowIndex+"]");
}
I initiated all the grid cells in SceneBuilder The gridpane has been created in SceneBuilder Then I created the anchorpanes for each cell in the controller class initialization:
for(int row=0;row<numRows;row++){
for(int col=0;col<numCols;col++){
AnchorPane slot=new AnchorPane();
slot.setStyle("-fx-border-color: black;-fx-border-width: 0.2;");
grid.add(slot,col,row);
}
}
I don't know if this is a bad approach but i am trying to learn. Please help me how to do this differently or why it is giving me null value. When the user clicks on one of the grid cells, i.e. they should be anchorpanes, I want the Anchorpane that they clicked or the grid cell row and column.