Hello, I was wondering how to set up a smartdashboard widget to loop continuesly? I know how to make a widget I’m just not sure if any of the functions are called repeatedly like a loop or they only run on call.
If memory serves, the SmartDashboard widgets are just Swing components. The constructor would be executed once during initialization, and then the drawing methods (paint, paintComponent, etc) are run periodically as determined by Swing and the OS. Doing any kind of looping or long-executing tasks in these places would cause significant slowness in the UI, unfortunately.
If you want something to update continuously you’re best off doing it from a background thread. The official camera widget does this to fetch new images: [source]](http://lhrobotics.svn.sf.net/viewvc/lhrobotics/trunk/extensions/camera/SquareTracker/src/edu/wpi/first/wpilibj/examples/WPICameraExtension.java?revision=214&view=markup)
(Note that this code is a snapshot from the smartdashboard svn as of last year, but I doubt all that much has changed since then. Also know that this code does some bad things like calling System.gc() which is a pretty terrible idea)
The images are fetched in the background and then a call to repaint() is queued in the UI thread with SwingUtils.invokeLater(). The repaint() method will then be called “later” which then displays the fetched image and in theory should never cause any noticeable lag in the UI.