Reputation: 65
I have an arrayList with a varying amount of names in the Array depending on how its used. I create JRadioButtons for one of the functions with the name of the arrayList such like:
for(int i = 0; i < m_fixtures.size(); i++){
panel.add(new JRadioButton(m_fixtures.get(i)));
}
Is there any way I can check what name has been assigned to that JRadioButton as i want to do something along the lines of
get the selected Jradiobuttons "label" and add do something to that data but I cannot figure out how to get the "label" assigned to it.
Upvotes: 0
Views: 250
Reputation: 2468
Component[] components = panel.getComponents();
for (Component singleComponent : components) {
if (singleComponent instanceof JRadioButton) {
JRadioButton jrb = (JRadioButton) singleComponent;
// println or whatever you want
System.out.println(jrb.getText());
}
}
Upvotes: 2