Java 下拉清单

发布于 2024-08-11 06:28:38 字数 612 浏览 7 评论 0 原文

我了解如何使用 JLists 但我想添加 JCheckBox添加到列表中并使其像下拉菜单一样。我在网上找到的最佳视觉表示是 dropdown-check-list

实现上述目标的最佳方法是什么? 我正在考虑 TableList。有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心清如水 2024-08-18 06:28:38

如果您使用的是 JList,那么只需更改 ListCellRenderer 以返回 JCheckbox 组件即可。

编辑:
对于 JCombobox,您可以使用 combobox.setRenderer(myListRenderer);

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

笔落惊风雨 2024-08-18 06:28:38

此代码片段可能帮助你。

基本思想是自己处理 actionPerformed 或 mouseClick 事件,并将相应项目的状态(选中/未选中)保存在您自己的数据结构中。您将能够使用该数据结构在下拉列表中呈现复选框

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文