简体   繁体   中英

Jtable losing multiple row selection,when button in one of the column is clicked

I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.

Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.

Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.

I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.

Thanks

If I understood your problem correctly then the solution is fairly simple.

First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.

To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.

A cleaner and more intuitive approach though would be to place the button outside of the JTable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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