Search code examples
javaswingfile-iojtableupdating

Update JTable through file


Alright so I'm reading some scores off of a text file and when the user is done playing the game, it asks you if you want to save the score or not, I only have one problem with this. It reads and writes fine to and front from the text file, it's just that the JTable isn't updating whenever a new score is added. The Object[][] is being read off a text file and I was just wondering if there was a method like "table.setData(Object[][] o);" sorta thing, any help would be greatly appreciated, thank you.


Solution

  • Just so you can accept an answer and keep your reputation up:

    It sounds like you need to set a DefaultTableModel.

    Then you can use ((DefaultTableModel) table.getModel()).setDataVector(yourData, columnHeaders);. With 'yourData' being an Object[][], and 'columnHeaders' Object[]

    That should do exactly what you need.