简体   繁体   English

从更新的 SQL 数据库刷新 JavaFX 场景?

[英]Refreshing JavaFX scene from updated SQL database?

I am currently writing a program which retrieves data from a SQL database and uses the data to populate a pie-chart on a JavaFX scene.我目前正在编写一个程序,该程序从 SQL 数据库中检索数据并使用该数据在 JavaFX 场景中填充饼图。 So far, this has been a success.到目前为止,这已经取得了成功。

What I am wondering is if it is possible to repopulate and refresh the pie chart as new data is entered into the database.我想知道的是,当新数据输入到数据库中时,是否可以重新填充和刷新饼图。 So far the only solution I have found is to close the program and reopen it, which is not really much of a solution.到目前为止,我找到的唯一解决方案是关闭程序并重新打开它,这并不是真正的解决方案。

I can provide my code if needed.如果需要,我可以提供我的代码。

Grateful for any tips you can give, thanks!感谢您提供的任何提示,谢谢!

What I am wondering is if it is possible to repopulate and refresh the pie chart as new data is entered into the database.我想知道的是,当新数据输入到数据库中时,是否可以重新填充和刷新饼图。

The beauty of graphs/Charts in FX is that they are all dynamic, and change. FX 中图形/图表的美妙之处在于它们都是动态的和变化的。

if you add new data to your dataCollection, or set your entire database to PieChart.setData(data);如果您向 dataCollection 添加新数据,或将整个数据库设置为 PieChart.setData(data);

You would have to set up a listener to listen in on your DB and changes, or listen to the changes on whatever is changing your DB.您必须设置一个监听器来监听您的数据库和更改,或者监听正在更改您的数据库的任何更改。 Is it external or internal to your Application?它是您的应用程序的外部还是内部?

If it's Internal than you can set up the listener with a flag and do it then, if it's External then you will either如果它是内部的,那么你可以用一个标志设置侦听器然后再做,如果它是外部的,那么你要么

  1. have to poll the database x seconds/minutes必须轮询数据库 x 秒/分钟
  2. somehow set up SQL code to update something in your application and set up a listener there (such as How to implement a db listener in Java )以某种方式设置 SQL 代码以更新应用程序中的某些内容并在那里设置一个侦听器(例如How to implement a db listener in Java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM