简体   繁体   English

如何在选择该表中的任何行后将JTable行设置为“未选定”状态?

[英]How to make a JTable row to an “unselected” state after selected any row in that table?

I'm developing a Java Swing application which contains a JTable . 我正在开发一个包含JTable的Java Swing应用程序。 By default, while launching the application for the first time, the call to the method jtable.getSelectedRow() or jtable.getSelectedColumn() returns -1, which means that no row selected at that moment. 默认情况下,在第一次启动应用程序时,对方法jtable.getSelectedRow()jtable.getSelectedColumn()的调用返回-1,这意味着此时没有选择任何行。 After user clicked any row or column, the call to the method jtable.getSelectedRow() or jtable.getSelectedColumn() returns the appropriate values of selected rows & columns. 用户单击任何行或列后,对方法jtable.getSelectedRow()jtable.getSelectedColumn()的调用将返回所选行和列的相应值。 What I actually need is that I want to set the selected row or column to -1 ie "no row or column selected state". 我真正需要的是我想将所选行或列设置为-1,即“没有行或列选择状态”。 How can I do this? 我怎样才能做到这一点?

The JTable method clearSelection will do what you want -- clear the selection of all the table's selected rows and columns. JTable方法clearSelection将执行您想要的操作 - 清除所有表的所选行和列的选择。 The JTable API is the place to look for methods such as these. JTable API是查找这些方法的地方。

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

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