Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with animated JLabel

843805Aug 13 2006 — edited May 15 2007
I've created an animated extension of the JLabel which imitates a "typewriter" effect. It works smoothly for single-line labels.
Here is a basic pseudo-code outline of how I went about doing it:
constructor(String fullText, int delay) {
  create swing timer
  start timer
}

//called by timer
actionPerformed() {
  if (all chars are printed)
    stop timer

  else {
    labelStr += fullText.charAt(pos);
    this.setText(labelStr);
    pos++;
  }
}
The problem is, whenever It recognises an HTML line break (to make it a multi-line label), all of the text gets bumped up. Here's a rough animation showing my animated label and a regular jlabel...
http://img223.imageshack.us/img223/8459/typewriteranizy1.gif
As you can see, once the line breaks are added to the animated label's text, all the text is moved up. This creates a choppy scrolling effect, something I'm trying to avoid at the moment.

Any ideas on how I could keep the animated text in a fixed position, so it doesn't scroll up like this?

I can provide source code if needed.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2007
Added on Aug 13 2006
8 comments
415 views