I have a settings tab in my program. The data you can set there, is not only changeable from this panel. That's why I want to reload this data like every 5 seconds. I think this has to be done with an extra Thread, but my knowledge about Threads is minimal. I already have a reload method for this purpose.
What should I use to do this (and how...)?
Use a ScheduledExecutorService:
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(yourRunnable, 5, 5, SECONDS);
Then reload your JPanel
in yourRunnable
(just follow the example from the JavaDocs).
but my knowledge about Threads is minimal...
paintComponent(...)
method, or perhaps better, in a BufferedImage that is then displayed inside of paintComponent(...)
.ScheduledExecutorService
as per syb0rg's answer (1+ to syb0rg's answer) that requests and obtains new data every 5 seconds.repaint()
from the Swing event thread after your data is changed. If using a SwingWorker, the process/publish method pair could help with this. You could publish your data to the Swing event thread with this.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With