As described in tuytuys question i get data from a jTable to an 2d array.
Object [][] newarr = null;
newarr = getTableData(jTable);
the code of getTableData:
public Object[][] getTableData (JTable table) {
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
int nRow = dtm.getRowCount();
int nCol = dtm.getColumnCount();
Object[][] tableData = new Object[nRow][nCol];
for (int i = 0 ; i < nRow ; i++){
for (int j = 0; j < nCol ; j++)
tableData[i][j] = dtm.getValueAt(i,j);
}
System.out.println(Arrays.asList(tableData));
return tableData;
}
The newarr 2d object array contains the data of the jTable, I have debugged it.
The question is: How may I get the string data from the 2d object array in which is the string from the cell of the jTable?
String s = newarr[0][1].toString();
for example is not working.
(String) newarr[0][1]instead of usingtoString()method from Object class