简体   繁体   English

如何从jComboBox查询jTable?

[英]How to query jTable from jComboBox?

I have some data in a jTable and want to query a category (Chairs, Desks, etc.) with a drop down box and a search button. 我在jTable中有一些数据,并想用一个下拉框和一个搜索按钮查询类别(椅子,桌子等)。 I want to have the user select a category, such as Desks, and click the jButton Available Furniture, and be shown a message like: "There are 5 desks. They are Small Office Desk, Large Office Desk, etc." 我希望用户选择一个类别,例如“办公桌”,然后单击“ jButton可用的家具”,并显示一条消息,例如:“有5张办公桌。它们是小型办公台,大型办公台等。” How can I do this? 我怎样才能做到这一点?

Here is a picture of the program with the data so you can see what I mean: 这是带有数据的程序的图片,因此您可以了解我的意思:

jTable with some information and furniture categories j带有一些信息和家具类别的表

https://i.stack.imgur.com/QzGJU.png

Maybe the easiest way to do this is to just "filter" the table when you do your search by the keyword. 可能最简单的方法是在通过关键字进行搜索时仅“过滤”表。

Read the section from the Swing tutorial on Sorting and Filtering for a working example. 阅读Swing教程中有关排序和过滤的部分,以获取一个有效示例。

You will just need to modify the code to get the search keyword from a combo box instead of a text field. 您只需要修改代码即可从组合框而不是文本字段中获取搜索关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM