Вот версия, использующая JCheckBox
:
import javafx.util.Pair;
public static <T> List<T> select(Component parent, String message, List<T> variants) {
List<Pair<JCheckBox, T>> boxes = variants
.stream()
.map(variant -> new Pair<>(new JCheckBox(String.valueOf(variant)), variant))
.collect(Collectors.toList());
JPanel panel = new JPanel(new GridBagLayout());
boxes.forEach(p -> panel.add(p.getKey(),
new GridBagConstraints(
0,
boxes.indexOf(p),
1,
1,
1.0,
1.0,
GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0),
0,
0
)
));
JOptionPane.showMessageDialog(parent, panel, message, JOptionPane.PLAIN_MESSAGE);
return boxes.stream()
.filter(p -> p.getKey().isSelected())
.map(Pair::getValue)
.collect(Collectors.toList());
}