twodayslate
twodayslate

Reputation: 2833

Java Dropdown Checklist

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?

Upvotes: 2

Views: 6268

Answers (2)

Suraj Chandran
Suraj Chandran

Reputation: 24791

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);

Upvotes: 5

Dmitry
Dmitry

Reputation: 3780

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

Upvotes: 4

Related Questions