-1

I have two JTable components, I want that if i click on any row of first table then, the elements having same ID in table 2 also, changes their background color.

I searched these while R&D

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

0
  1. Add a ListSelectionListener to the first table. It will generate an event whenever the selection of a row is changed

  2. When the event is generated you clear the selection of the second table and then iterate through all the rows of the table finding rows with the same id. Then you can invoke the changeSelection(...) method on that table.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Sir, I am not getting the exact requirements. My problem is, that i have two jtable on a jframe, now i am able to select rows from the first table but i want that when i click to the first row having id "1" of the first table then the rows containing id = 1 gets highlighted automatically. – Amit Kashyap Jul 06 '18 at 07:38
  • And that is the solution I provided you with. I'm not sure what you don't understand about my suggestion? Did you add a ListSelectionListener to the first table? Did you write code to get the ID of the selected row? Did you write code to search the second table for rows containing the ID? Did you then change the selection of those rows? – camickr Jul 06 '18 at 14:10