Read out if RadioButton is selected in other controller [duplicate]
Read out if RadioButton is selected in other controller [duplicate]
This question already has an answer here:
I am currently working on JavaFX Project where i need to access an FXML Object from another class to show a ComboBox if the RadioButton is selected.
So for example I have 4 RadioButtons called
//First Controller
@FXML
private RadioButton radioButtonS1, radioButtonS2, radioButtonS3, radioButtonS4;
I have to read them out in the other Controller to set them visible my ComboBoxes are called:
//Second Controller
@FXML
private ComboBox comboS1A, comboS1E1, comboS1E2;
@FXML
private ComboBox comboS2A, comboS2E1, comboS2E2;
@FXML
private ComboBox comboS3A, comboS3E1, comboS3E2;
@FXML
private ComboBox comboS4A, comboS4E1, comboS4E2;
So how can I see in the SecondController which RadioButton is selected in the FirstController and make the CombBox visible?
Thanks.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1 Answer
1
You can create static int variable, and this variable contain the selected RadioButton number
public static int selectedCombo = -1;
and put this lines in the method initialize of the first controller
radioButtonS1.setOnAction(e->
selectedCombo = 0;
);
radioButtonS2.setOnAction(e->
selectedCombo = 1;
);
...
in the second controller you need to make switch:
switch(selectedCombo)
case 0:
// make visible the comboBox 1
break;
case 1:
// make visible the comboBox 2
break;
...
There are a lot of other questions/answers for this subject on StackOverflow. I recommend checking out this one: stackoverflow.com/questions/14187963/…
– Zephyr
Aug 28 at 15:54