Read data from a JTable created from AbstractTableModel

If you have a JTable in Java created with an AbstractTableModel, you can read the data from it, using following:

int rowCount = testTable.getRowCount();
for (int i = 0; i < rowCount; i++) {
   String mColumn1 = (String) testTable.getModel().getValueAt(i, 0);
   String mColumn2 = (String) testTable.getModel().getValueAt(i, 1);
}

Alternatively, you could also try where the JTable is within a Panel:

int rowCount = testTable.getRowCount();
for (int i = 0; i < rowCount; i++) {
   JTable myTable = myPanel.testTable;           //<-----

   String mColumn1 = (String) myTable.getModel().getValueAt(i, 0);
   String mColumn2 = (String) myTable.getModel().getValueAt(i, 1);
}

Leave a Reply

  

  

  

Blue Captcha Image
Refresh

*

October 2019
M T W T F S S
« Sep    
 123456
78910111213
14151617181920
21222324252627
28293031