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.





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




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;
...

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?