Java中的Repaint和paintComponent()
我正在从传感器连续读取数据,并希望使用该数据绘制图表。我已经创建了该图表,但是,系统仅在第一次读取时绘制该图表,不会动态更改绘图。
我使用了paintComponent(),并尝试使用重绘来更新它。我发现虽然数据不断更新,但程序执行paintComponent()的次数不会超过一次。
任何解决该问题的建议将不胜感激。
I am reading data continuously from a sensor and want to plot chart using that data. I already create that chart, however, system draws that chart for only the first reading, doesn't change the plot dynamically.
I used paintComponent() and I try to update that by using repaint. I have found that though data updates continuously, but the program doesn't execute paintComponent() for more than one time.
any suggestion to solve that problem would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
validate()
或revalidate()
,然后
调用
repaint()
希望这会有所帮助。
有用的链接:http://docs.oracle。 com/javase/6/docs/api/javax/swing/JComponent.html#revalidate()
Try
validate()
orrevalidate()
and then,
call
repaint()
Hope this will help.
Helpful Link : http://docs.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#revalidate()