Issue
I am trying to set up a method used by three different buttons. I want to load one of three different views depending on which of them is pressed. To do so, I thought about passing as an argument the button itself. But I was unable, due to javaFX not recognising the method with the new argument.
How can I get the fx:id
of the caller button so I can make the distinction between each of them? Here's what I got this far. I just need to initialize pressed
variable so it will do its thing.
if (pressed == edgeModify){
loader = new FXMLLoader(getClass().getResource("/digitalia/view/edgeView.fxml"));
} else if (pressed == sectionModify){
loader = new FXMLLoader(getClass().getResource("/digitalia/view/sectionView.fxml"));
} else {
loader = new FXMLLoader(getClass().getResource("/digitalia/view/LayerView.fxml"));
}
Solution
You can get the id of the button as below:
Button btn = (Button) event.getSource();
String id = btn.getId();
An easier approach would just be to use different handlers for the buttons.
Answered By - Calvin Iyer