如何在按下键时选择完整的行,然后搜索存储在JTable中的元素并选择该行? [英] how to select a complete row on pressing a key and then search the element stored in the JTable and select that row?
问题描述
我有一个JTable和JLabel,我在表中放了一些值! 我想在该表中实现搜索,然后从JLabel上的搜索值中设置值.
i have a JTable and JLabel , i have put some values in the Table ! i want to implement search in that table and then set the value from the searched value on the JLabel.
假设我键入'f',则myfunction将搜索myTable的行和第0列中的值以f开头的位置,因此我将获得该行的值!现在我要选择/突出显示整个行并在JLabel上打印值.
suppose i type 'f' so myfunction will search where in myTable's row and 0th column the value starts with f , thus i ll get that row value ! now i want to select/highlight that entire row and print the value on JLabel.
我不知道如何突出显示这一行! 有没有更好的搜索方法,我已经阅读了有关SwingX的信息,但是我没有找到如何实际使用JXTables的方法.
I don't know how to highlight this row! is there any better method to do searching , i have read about SwingX , but i did not find how to actually use JXTables.
推荐答案
也许最好使用JTable的filtering
功能.
Maybe it would be better for you to use the filtering
capabilities of JTable.
排序和过滤上的Swing教程给出了一个可行的示例,说明如何完成此操作以过滤以您在文本字段中输入的文本开头的所有行.
The Swing tutorial on Sorting and Filtering give a working example on how this can be done to filter all the rows that start with the text entered in your text field.
我不理解您有关更新标签"的问题,因为可能有多个行可以以搜索字符串开头.
I don't understand your question about updating a "label", since it is possible that multiple rows could start with the search string.
这篇关于如何在按下键时选择完整的行,然后搜索存储在JTable中的元素并选择该行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!