选择多行JTable [英] Selecting multiple rows of JTable
本文介绍了选择多行JTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用JTable来显示数据库中的内容。我想为用户提供设施,以便他可以使用shift +箭头键选择他想要的行数,然后使用提供的删除选项删除这些记录。请提供一个小例子。
I'm currently using JTable to show the contents in database. I want to provide the facility for user so that he can select the number of rows he wants using shift+arrow key and then later on delete those records using the option provided for deletion. Please provide a small example.
推荐答案
您需要允许多项选择:
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
然后你需要编写适当的选择监听器。这有点难,试着找到谷歌相关的解决方案。您可以查看选择监听器的示例。
Then you need to write appropriate selection listener. It's a bit harder, try to find in google related solutions. You can look at an example of selection listener.
这篇关于选择多行JTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文