[英]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.
它可以在文本文件中进行读写操作,只是每次添加新乐谱时JTable都不会更新。 The Object[][] is being read off a text file and I was just wondering if there was a method like "table.setData(Object[][] o);"
正在从文本文件中读取Object [] [],而我只是想知道是否存在类似“ table.setData(Object [] [] o);”的方法。 sorta thing, any help would be greatly appreciated, thank you.
有点事情,任何帮助将不胜感激,谢谢。
Just so you can accept an answer and keep your reputation up: 这样您就可以接受答案并保持声誉:
It sounds like you need to set a DefaultTableModel
. 听起来您需要设置
DefaultTableModel
。
Then you can use ((DefaultTableModel) table.getModel()).setDataVector(yourData, columnHeaders);
然后可以使用
((DefaultTableModel) table.getModel()).setDataVector(yourData, columnHeaders);
. 。 With 'yourData' being an
Object[][]
, and 'columnHeaders' Object[]
其中'yourData'为
Object[][]
和'columnHeaders'Object Object[]
That should do exactly what you need. 那应该完全满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.