将 Jfreechart 与下拉菜单集成
有没有办法将Jfreechart与下拉菜单集成?我想根据用户输入更新图表。 我们还有哪些其他选择来做到这一点?
Is there a way to integrate Jfreechart with drop-down menu? I want to update the chart depending on the user input.
What other options do we have to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的意思是当用户选择一个菜单项时,绝对是这样。您可以在任何事件发生时修改您的图表,您只需监听它即可。在你的情况下,它可能看起来像这样。
http://www.java2s.com/Tutorial/Java/0240__Swing/ListeningtoJMenuItemEventswithanActionListener.htm
如果您需要执行昂贵的操作来刷新图表,例如长时间运行DB 查询,那么您可能需要为其创建并启动一个后台线程,以保持 UI 响应。您需要注意您正在做什么以及您是在主事件调度线程还是后台线程中操作。如果您尝试在后台线程中执行 GUI 操作,则可能会发生不好的事情,但您应该能够安全地修改图表的状态。
Assuming you mean when the user selects a menu item, absolutely. You can modify your chart anytime some event happens, you just have to be listening for it. In your case it might look something like this.
http://www.java2s.com/Tutorial/Java/0240__Swing/ListeningtoJMenuItemEventswithanActionListener.htm
If you need to do an expensive operation to refresh your chart, like a long running DB query, then you'll probably want to create and start a background thread for it to keep your UI responsive. And you'll need to be mindful about what you're doing and whether you're operating in the main event dispatching thread or the background thread. Bad things can happen if you're trying to do GUI stuff in the background thread but you should be able to safely modify the state of your chart.