0

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.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Josh M
  • 11,611
  • 7
  • 39
  • 49
  • You want to add row's to the JTable's TableModel, often a DefaultTableModel object. If you need more help on this, you'll have to tell us more of the details of your code and your problem. A lot more. – Hovercraft Full Of Eels Apr 28 '12 at 18:54
  • for better help sooner edit your question with a [SSCCE](http://sscce.org/) demonstrated your issue inc. AbstractTableMolde's method `table.setData(Object[][] o)` – mKorbel Apr 28 '12 at 18:58
  • Alright nvm, I fixed it, all I needed was that DefaultTableModel object, there's a method called setDataVector(Object[][] data, Object[] columnNames); thank you – Josh M Apr 28 '12 at 19:00
  • Also consider `java.util.prefs.Preferences`, mentioned [here](http://stackoverflow.com/a/9481515/230513). – trashgod Apr 29 '12 at 01:56

1 Answers1

0

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.

Andy
  • 3,600
  • 12
  • 53
  • 84