I have a list of checkboxes, but I can not make multi selection from this list, it disables the previous selection when I check a new box. how can I change my code? or if it looks ok and by accident I do something wrong somewhere else in my code.
public JPanel createMultiMenu(ArrayList<String> domainItems) {
checkBoxMenuPanel = new JPanel();
checkBoxMenuPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
gbc.anchor = GridBagConstraints.WEST;
ButtonGroup group = new ButtonGroup();
for (String item : domainItems) {
JCheckBox checkBox = new JCheckBox(item);
group.add(checkBox);
checkBoxMenuPanel.add(checkBox,gbc);
}
return checkBoxMenuPanel;
}
The problem is that you are using ButtonGroup, which treats objects placed in it as radiobuttons (you can only select one at a time).
Instead try just adding them to the JPanel.
Something like that.