简体   繁体   English

选择多行JTable

[英]Selecting multiple rows of JTable

I'm currently using JTable to show the contents in database. 我目前正在使用JTable来显示数据库中的内容。 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. 我想为用户提供设施,以便他可以使用shift +箭头键选择他想要的行数,然后使用提供的删除选项删除这些记录。 Please provide a small example. 请提供一个小例子。

You need to allow multiple selection: 您需要允许多个选择:

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 . 您可以查看选择侦听器的示例

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

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