Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to update Figure with a timer?(When I trt to use a javax.swing.Timer I get an exception.)
How to update Figure with a timer? [message #631145] Wed, 06 October 2010 10:39 Go to next message
Mikkel Jonassen is currently offline Mikkel JonassenFriend
Messages: 24
Registered: September 2010
Junior Member
Hi

I have a Figure containing a RectangleFigure and a Label. I have added a listener to the label, so when I press on it it change the text to "Mouse Down" and when I release is change the text to "Mouse Up".

I am using this to change the labe:
label.setText("Mouse Down")

- Thats works fine.

But now I want a timer to update the label every 3seconds. I have tried with the javax.swing.Timer, but each time the Timer is trigger an event and the run method is called I am trying to do the same:
label.setText("Update Time Total = " +count)

But then I get the Exception:

org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.draw2d.DeferredUpdateManager.sendUpdateRequest(D eferredUpdateManager.java:258)
at org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU pdateManager.java:244)
at org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De ferredUpdateManager.java:133)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1448)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
at org.eclipse.draw2d.Label.setText(Label.java:630)
at figures. ClockFigure$FigureTimer.actionPerformed(ClockFigure.java:202 )
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


So how do I update the label correctly?

Thanks for your help.


Re: How to update Figure with a timer? [message #631294 is a reply to message #631145] Wed, 06 October 2010 19:56 Go to previous message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 06/10/2010 11:39, Mikkel Jonassen wrote:
> Hi
>
> I have a Figure containing a RectangleFigure and a Label. I have added a
> listener to the label, so when I press on it it change the text to
> "Mouse Down" and when I release is change the text to "Mouse Up".
>
> I am using this to change the labe:
> label.setText("Mouse Down")
>
> - Thats works fine.
>
> But now I want a timer to update the label every 3seconds. I have tried
> with the javax.swing.Timer, but each time the Timer is trigger an event
> and the run method is called I am trying to do the same:
> label.setText("Update Time Total = " +count)
>
> But then I get the Exception:
>
> org.eclipse.swt.SWTException: Invalid thread access
> at org.eclipse.draw2d.DeferredUpdateManager.sendUpdateRequest(D
> eferredUpdateManager.java:258)
> at org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU
> pdateManager.java:244)
> at org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De
> ferredUpdateManager.java:133)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1448)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1450)
> at org.eclipse.draw2d.Label.setText(Label.java:630)
> at figures. ClockFigure$FigureTimer.actionPerformed(ClockFigure.java:202 )
> at javax.swing.Timer.fireActionPerformed(Unknown Source)
> at javax.swing.Timer$DoPostEvent.run(Unknown Source)
> at java.awt.event.InvocationEvent.dispatch(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
>
>
> So how do I update the label correctly?
>
> Thanks for your help.
>
>
>

Have you thought about using the method:

public void timerExec (int milliseconds, Runnable runnable)

in the org.eclipse.swt.widgets.Display class instead of the Swing Timer?

PB
Previous Topic:How to update EditParts as contet of a GraphicalViewer?
Next Topic:Repeating/Streching with ImageFigures
Goto Forum:
  


Current Time: Tue Nov 25 02:05:53 GMT 2014

Powered by FUDForum. Page generated in 0.01770 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software