开发者

Java Dropdown Checklist

开发者 https://www.devze.com 2022-12-11 19:10 出处:网络
I understand how to mak开发者_JAVA技巧e 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

I understand how to mak开发者_JAVA技巧e 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消