aspose file tools*
The moose likes JavaFX and the fly likes Timer exception when adding shapes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Timer exception when adding shapes" Watch "Timer exception when adding shapes" New topic
Author

Timer exception when adding shapes

Casey Clayton
Ranch Hand

Joined: Feb 17, 2014
Posts: 41
Ok I am having an issue with a exception when trying to add new shapes to my JavaFx program. I have a randomizer that will randomly create a new Box object, which is converted to a rectangle for JavaFx use by a method I wrote, which all works fine. But when I setup the timer everything will run perfectly fine the first time through but then fails when it gets to this line when the timer kicks in. This is what the entire method looks like.



Here is using a timer to call the generateShapes method every 2 seconds or so.(As you notice I have a while loop that is commented out, which works perfectly fine but I need a timer which is causing the Thread exception.


If you need more information then let me know.
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 157
    
    9
Wrap the contents of your run method in Platform.runLater to put it on the JavaFX Application thread. Or remove the Timer and replace it with a Timeline.
Casey Clayton
Ranch Hand

Joined: Feb 17, 2014
Posts: 41
John Damien Smith wrote:Wrap the contents of your run method in Platform.runLater to put it on the JavaFX Application thread. Or remove the Timer and replace it with a Timeline.


Ok so I switched the method over to this but it's saying "void" type not allowed here, what am I doing wrong?

John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 157
    
    9
If you want to stick with a timer, see this StackOverflow answer on timers and JavaFX:


Though, I'd still be inclined to prefer a Timeline based approach as outlined in Tomas's answer to the same question:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timer exception when adding shapes