让 jcombobox 过滤 jtable

发布于 2024-07-25 10:28:55 字数 294 浏览 2 评论 0原文

遵循本教程 http://www.netbeans.org /kb/docs/java/gui-db-custom.html#enhancements

它展示了如何使用文本框过滤掉主表。 谁能指导我如何做类似的事情,但使用下拉菜单来测试特定列?

(即国家/地区下拉列表,按国家/地区列进行过滤?

谢谢

following this tutorial http://www.netbeans.org/kb/docs/java/gui-db-custom.html#enhancements

it shows how to use a textbox to filter out the master table. Could anyone instruct me on how to do a similiar thing but use a dropdown to test against a specific column?

(ie a dropdown of countries, to filter by the country column?

thanks

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

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

发布评论

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

评论(1

喜你已久 2024-08-01 10:28:55

取决于下拉列表的来源。
我假设下拉列表不用作 Jtable 本身的一部分,而只是显示来自一列数据的唯一数据列表?
在这种情况下,您可以获取 Jtable 的数据模型,然后遍历特定列中的所有单元格,将它们放入以字符串作为键的哈希图中。 这样您就有了一个(未过滤的)唯一字符串列表,可以用作下拉框的数据模型。
您可以将模型侦听器附加到 talbedatamodel 以了解列表何时也必须更新。

depending on what the source is for the dropdown.
i assume the dropdown isn't used as part of the Jtable itself, but merely shows a list of unique data coming from one column of data?
in that case, you could get the Jtable's datamodel, and then walk through all the cells in the particular column, putting them in a hashmap with the string as the key. that way you have a list of (unfiltered) unique strings to use as the datamodel for the dropdownbox.
You could attach a model listener to the talbedatamodel to know when your list has to be updated as well.

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