Restart JPanel every X seconds (using threads?)

I have a settings tab in my program. The data that you can install there is not only changed from this panel. So I want to reload this data every 5 seconds. I think this needs to be done with additional Thread, but my knowledge of Threads is minimal. For this purpose, I already have a way to reboot.

What should I use for this (and how ...)?

+5
source share
3 answers

Use ScheduledExecutorService :

 private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
 scheduler.scheduleAtFixedRate(yourRunnable, 5, 5, SECONDS);

Then reload JPanelin yourRunnable(just follow the JavaDocs example).

+4
source

but my knowledge of threads is minimal ...

  • , Java Concurrency Tutorial .
  • concurrency Swing .
  • JPanel paintComponent(...) , , , BufferedImage, paintComponent(...).
  • , SwingWorker. java.util.Timer ScheduledExecutorService syb0rg ( 1+ syb0rg), 5 .
  • repaint() Swing . SwingWorker, / . Swing .
+5

You can use Timerto periodically update your data.

0
source

All Articles