Hello everyone, I am trying to update a JTable after a user clicks a button.

I have a bunch of data in a TreeMap, which I then convert to a String[][], and pass to a DefaultTableModel, and then use that DefaultTableModel in the JTable. When the user clicks a button, they add data to the TreeMap. I then convert the TreeMap into a String[][]. I need some way of passing the data in the updated String[][] to the JTable, and refreshing the JTable.

If anyone has any ideas, please let me know, I've been stuck on this for hours, and nobody on other forums seems to know what to do. I will happily provide any other explainations or code if necessary.

Thanks!

I don't know that this is the best way to do it, but why not use a for loop that goes through the String[][] and setValueAt(Object, row,column) to update the JTable.

I can't do that because there will be about 1000 items, and sometimes the number of rows in the JTable will change. But thanks for the reply.

Awesome, that's exactly what I was looking for. I had been looking through JTable for something like "setTableModel" but I couldn't find it because that's not quite what it was called.

Things are working great now, thanks.

This article has been dead for over six months. Start a new discussion instead.