Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Animating text  RSS feed

 
James Filson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to create a method that can accept a string and then display it in a 'handwriting' manner, painting one letter to the JPanel at once with a short delay in between each.



This is what I have created as a simple test, however it doesn't update the Label until the loop has completely finished. I'm stumped as to why, do I need a repaint method after each setText?

Thank in advance

James
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you invoking the setText() method? As a static method? That method ought not to be static.

There may be more things wrong which I haven't noticed yet.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
however it doesn't update the Label until the loop has completely finished.


Because you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency for more information.

The proper way to do animation is to use a Swing Timer. The tutorial also has a section on Timers.
 
James Filson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
however it doesn't update the Label until the loop has completely finished.


Because you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency for more information.

The proper way to do animation is to use a Swing Timer. The tutorial also has a section on Timers.

Ah ha! Read up on it and an hour later I had it working... thank you

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!