简体   繁体   English

按下JButton时找出JTable中先前选择的行

[英]Find out previously selected row in JTable when pressing JButton

I want to implement a JButton ("Delete row") to delete the row currently selected in a JTable. 我想实现一个JButton(“删除行”)以删除当前在JTable中选择的行。

JTable.getSelectedRow() works within the selection listener, but does not work out of it. JTable.getSelectedRow()在选择侦听器中有效,但不能在选择侦听器中有效。

When the user presses the "Delete row", how can I figure out which row has been selected? 当用户按下“删除行”时,如何确定选择了哪一行?

PD: So far, my idea is to create a variable, automatically updated each time the selection listener is called, and when the user presses the button check the value of this variable. PD:到目前为止,我的想法是创建一个变量,该变量在每次调用选择侦听器时自动更新,并在用户按下按钮时检查此变量的值。 However, it does not look very nice... 但是,它看起来不太好...

While going through my ListSelectionListener inner class, I found the next line 在遍历ListSelectionListener内部类时,我找到了下一行

m_view.getInputsTable().clearSelection();

Comment the line, and keep working :D 评论该行,并继续工作:D

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

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