You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2011/01/19 01:46:38 UTC

UI thread timer?

Is there a sanctioned timer class to use that fires in the UI thread?  I
tried using javax.swing.Timer, which sort of works (in that it doesn't
complain about being on the wrong thread), but actions taken by the timer
callback don't manifest in the UI until the next time something runs code in
the UI thread (in my case, a GetQuery).

Re: UI thread timer?

Posted by Chris Bartlett <cb...@gmail.com>.
Bill,

Are you aware of the '*Callback' methods in
org.apache.pivot.wtk.ApplicationContext?

http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ApplicationContext.html
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Chris

On 19 January 2011 07:46, Bill van Melle <bi...@gmail.com> wrote:

> Is there a sanctioned timer class to use that fires in the UI thread?  I
> tried using javax.swing.Timer, which sort of works (in that it doesn't
> complain about being on the wrong thread), but actions taken by the timer
> callback don't manifest in the UI until the next time something runs code in
> the UI thread (in my case, a GetQuery).

Re: UI thread timer?

Posted by Bill van Melle <bi...@gmail.com>.
Thanks!  ApplicationContext.scheduleRecurringCallback is exactly what I was
looking for.  Even easier to use than the Swing timer.

(Searching on "timer" was apparently not the right strategy in this case.)

Re: UI thread timer?

Posted by Greg Brown <gk...@verizon.net>.
FYI, the problem isn't that the Swing timer is on the "wrong" thread - it is that the Pivot runtime needs to handle the callback so that the layout system can be invoked properly. In most cases, you are probably going to do something in your callback that will invalidate your UI and trigger a relayout. Using the ApplicationContext methods as Chris suggested ensures that this will happen, whereas using the Swing timer it won't.

On Jan 18, 2011, at 7:46 PM, Bill van Melle wrote:

> Is there a sanctioned timer class to use that fires in the UI thread?  I tried using javax.swing.Timer, which sort of works (in that it doesn't complain about being on the wrong thread), but actions taken by the timer callback don't manifest in the UI until the next time something runs code in the UI thread (in my case, a GetQuery).