JComboBox<JCheckBox> cb = new JComboBox<JCheckBox>();
cb.add(cbEasy = new JCheckBox("EASY", false));
cb.add(cbDifficult = new JCheckBox("DIFFICULT", false));
JMenu menu = new JMenu("Difficulty");
JRadioButtonMenuItem item1 = new JRadioButtonMenuItem("Easy");
JRadioButtonMenuItem item2 = new JRadioButtonMenuItem("Normal");
JRadioButtonMenuItem item3 = new JRadioButtonMenuItem("Hard");
ButtonGroup group = new ButtonGroup();
group.add(item1);
group.add(item2);
group.add(item3);
menu.add(item1);
menu.add(item2);
menu.add(item3);
1条答案
按热度按时间qfe3c7zg1#
如果你想做一个带有复选框的菜单,最好使用带有JCheckBoxMenuItems的JMenu,或者更确切地说,如果选择是互斥的,则使用JRadioMenuItems: