With the above code i want to close the popup right after click on one of the radio buttons but the popup stays open.
Is there something build-in in swing or must i call actionPeformed and close the popup explicity ?
public class NewClass extends JFrame {
NewClass() {
setSize(100,100);
JPopupMenu pop = new JPopupMenu();
JRadioButton log1 = new JRadioButton("Level 1");
pop.add(log1);
JRadioButton log2 = new JRadioButton("Level 2");
pop.add(log2);
JPanel p = new JPanel();
add(p);
p.setComponentPopupMenu(pop);
}
public static void main(String[] args) {
new NewClass().setVisible(true);
}
}
look at JRadioButton#addItemListener() and check if ButtonGroup is usefull in your case
EDIT:
I don’t know…, good question, but if you adds
JRadioButtonto theJMenuItemthen is build-in look here