无法更新子 JFrame 中的结果表
我有一个交互式的主 JFrame,即用户设置不同的选项。按下“运行”按钮后,根据用户首选项创建配置文件,并将其传递到程序的下一部分。完成一些计算并将结果写入文件。程序的第三部分读取结果文件并对其进行总结。
然后打开由 JTabbedPane 和几个 JPanel 组成的子 JFrame。每个 JPanel 都显示不同的 JTable 以及相关信息。子 JFrame 具有 DISPOSE_ON_CLOSE 方法,否则两个 JFrame 都会被终止。
所以问题是,如果用户更改某些选项,再次运行程序,新的子 JFrame 实际上并不是新的 - 它只显示第一次运行的信息。我试过了:
invalidate()
revalidate()
repaint()
没有任何帮助。我不知道问题出在哪里。我非常确定在更改选项后会读取新的结果文件,因为它会在控制台中打印。
可能其他重要的事情是首先创建表,并且子 JFrame 被最新调用。
I have a main JFrame that is interactive, i.e. user sets different options. After pressing a "run" button config file is create from user preferences and it is passed to next part of the program. Some calculations are done and the results are written to a file. Third part of the program reads the results file and summarizing them.
Then child JFrame is opened consisting of JTabbedPane with several JPanels. Each of the JPanels shows different JTables with the relevant info. The child JFrame has DISPOSE_ON_CLOSE method otherwise both JFrames are killed.
So the problems is that if user change some options, run the program again, the new child JFrame is not actually new - it shows only the info from first run. I've tried:
invalidate()
revalidate()
repaint()
Nothing helps. I don't know where the problem is. I'm pretty sure that after changing options the new results file is read because it prints in the console.
May be other important thing is that the tables are created first and child JFrame is call latest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为您的代码中的某处有:
这不会将表添加到 GUI。您应该通过执行以下操作来刷新现有表中的数据,而不是创建新表:
这将导致自动重新绘制数据。不需要 invalidate()、revalidate() 或 repaint()。
Probably because somewhere in your code you have:
This does not add the table to the GUI. Instead of creating a new table you should refresh the data in the existing table by doing:
This will cause the data to be repainted automatically. There is no need for invalidate(), revalidate() or repaint().