Lets say I have two buttons in the FXML for instance:
<Button fx:id="button1" onAction="#onClick1" prefHeight="134.0" prefWidth="134.0"></Button>
<Button fx:id="button2" onAction="#onClick2" prefHeight="134.0" prefWidth="134.0"></Button>
and I want to have it as an array of buttons in the controller class. How can I go about and do that? I have tried:
public Button button1, button2;
public Button[] arrayButtons = {button1, button2}
and also tried making a method:
public class controller {
public Button button1, button2;
public Button[] arrayButtons;
public void initializeButtonArray() {
arrayButtons = new Button[2];
arrayButtons[1] = button1;
arrayButtons[2] = button2;
}
}
none of these work as it gives me a runtime exception when I try to do something with the array (ie. arrayButton[1].setText("Test")):
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
How can I go about and have an array of Button where the elements are from fx:id?
initializeButtonArraytoinitialize(or call theinitializeButtonArray()method frominitialize()).