how do I get an element in JavaFx using an id?
I am new to FXML and I am trying to create a handler for all of the button clicks using a switch . However, in order to do so, I need to get the elements using and id. I have tried the following but for some reason (maybe because I am doing it in the controller class and not on the main) I get a stack overflow exception. public class ViewController { public Button exitBtn; public ViewController() throws IOException { Parent root = FXMLLoader.load(getClass().getResource("mainWindow.fxml")); Scene scene = new Scene(root); exitBtn = (Button) scene.lookup("#exitBtn"); } } So how will I get an