Is it good to use a swing timer outside of a swing?

As the name says, is it acceptable to use a swing timer in a non-swing application?

Or am I better off writing my own using a separate thread?

I don't know what disadvantages the swing timer might have, but I tend to use things that already exist.

+3


source to share


2 answers


In general, we recommend using Swing timers rather than generic timers for GUI-related tasks, since all Swing timers share the same pre-existing timer thread and the GUI-related task is automatically executed on the event dispatch thread. However, you can use a general-purpose timer if you do not plan to touch the GUI from the timer or require lengthy processing.

Documentation: http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html



I recommend using util.Timer

.

+4


source


No, only use the Swing timer when you are working on an EDT . Other than that, you can use java.util.Timer

.



Also, Swing Timers are slower than Usage Timers because they are designed to work with a GUI.

+2


source







All Articles