Question

I understand how to make a multiple-select list box using JLists but I want to add JCheckBoxes to the list and make it dropdown like. The best visual representation I have found online is dropdown-check-list.

What would be the best way to accomplish the above? I was thinking of a TableList. Any suggestions?

Was it helpful?

Solution

This code snippet may help you.

The basic idea is to handle actionPerformed or mouseClick events by yourself and keep states of the corresponding items (checked/unchecked) in your own data structure. You'll be able to use that data structure for rendering checkboxes in a dropdown

OTHER TIPS

If you are using JList, then its as simple as changing the ListCellRenderer to return a JCheckbox component.

EDIT: For JCombobox, you can use combobox.setRenderer(myListRenderer);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top