I need to create a comboBox with multiple chechboxes in my java swing gui. My first thought was to create a custom comboBox with its own CellRenderer but then I decided to go with a more "friendly" solution and use JMenu with JCheckBox items inside.
The problem is, that when I create the menu and place it inside my JPanel, the menu is not active and it does not open when being clicked. Any ideas what may be the cause of this behavior? Is it even possible to use JMenu like this?
This is a sample of my code:
JMenu menu;
panelCenter.add(new JLabel("Selection"));;
panelCenter.add(prepareSelection(menu));
private JMenu prepareSelection(JMenu menu) {
menu = new JMenu("Select items");
for (int i = 0; i < 10; i++) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem("item " + i);
menu.add(item);
}
return menu;
}
Thanks for any help!