bruh bruh - 1 month ago 5
Java Question

get data from a column then select whole row where the data belongs

for example this is my

JTable
:


ID|NAME|AGE

001|anna|18

002|tony|25


now i want that the user will enter the ID, then convert that ID into which row it belongs. now i'm using
setRowSelectionInterval()
to select the row without really selecting it in the actual row. but i don't know how to get the data from a column, then convert it into a row where it belongs, so i can put in in the
setRowSelectionInterval()
. thank you for any of your help :)

Answer

Write a loop.

  1. You can use the getRowCount() method of the table to iterate through each row.

  2. Then you use the getValueAt(...) method to get the value of the ID in the row for the specific column.

  3. When you find a match you use the row index for the setRowSelectionInterval(...) method.

Comments