I understand how to mak开发者_JAVA技巧e a multiple-select list box using JLists
but I want to add JCheckBox
es 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?
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);
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
精彩评论