how to select a complete row on pressing a key and then search the element stored in the JTable and select that row?

放肆的年华 提交于 2019-12-25 03:54:46

问题


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.

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.

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.


回答1:


Maybe it would be better for you to use the filtering capabilities of JTable.

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.



来源:https://stackoverflow.com/questions/24084922/how-to-select-a-complete-row-on-pressing-a-key-and-then-search-the-element-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!