Search code examples
javaswingjcombobox

How to create Combobox with multiselection?


I need to create a combo box with multi-selection, how to achieve that?


Solution

  • There are a few basic problems with creating custom combobox popup content (like a list with multiselection):
    1. Default UI suggests JList usage as the content so to change that behavior you will have to change the whole ComboBoxUI
    2. You cannot simply change the default combobox list into multiselection one due to the fact that only one value gets "selected" at the end and list has default rollover selection mouse listener, that will make you unable to choose more than one element

    So i'd reccomend you to use simple JList instead of combobox or look into using some extended components libraries like JideSoft - they have this component and lots more which you won't be able to quickly create using Swing features.