GUI running at 30 fps?

后端 未结 1 643
南旧
南旧 2020-11-27 22:40

While testing some real-time simulation code which uses a Swingworker I noticed my GUI always seems to run at 30 fps, no more, no less. I update the GUI everytime the user i

相关标签:
1条回答
  • 2020-11-27 23:01

    It turns out SwingWorker posts instances of Runnable to the EventQueue using a javax.swing.Timer with exactly that DELAY.

    private static class DoSubmitAccumulativeRunnable 
          extends AccumulativeRunnable<Runnable> implements ActionListener {
        private final static int DELAY = (int) (1000 / 30);
        ...
    }
    

    You can get a higher frame rate, but not with javax.swing.SwingWorker. You can build SwingWorker from source, but eventually you saturate the thread with instances of Runnable. One alternative is to run the model flat out and sample it periodically, as shown here.

    0 讨论(0)
提交回复
热议问题