How can I use a RadioButton to select what appears in the combobox that is displayed after i.e. click (buttons(male) or (female)) and get a combo box drop down displaying either (combobox(Mr, master) or (Mrs,miss))
Ive spent the past few hours trying to figure out something at would work. I thought all I needed was to create an actionListener to set a different array to the combobox depending on what button is clicked but I seemed to get nowhere.
This is what I had so far
`male = new JRadioButton("Male", true);
female = new JRadioButton("Female", false);
add(male);
add(female);
buttonGroup = new ButtonGroup();
buttonGroup.add(male);
buttonGroup.add(female);
radioListener radio = new radioListener();
male.addActionListener(radio);
female.addActionListener(radio);
JComboBox nameTitle = new JComboBox();
add(nameTitle);`
}
public class radioListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(male.isSelected()) nameTitle.setSelectedItem(maleTitles);
if(female.isSelected()) nameTitle.setSelectedItem(femaleTitles);
}
}