Hey gurus, I got a question... What is the popular logic to automatically scroll text thru a text field, either vertically or horizontally. I don't mean with scroll bars but like "tickers" that you see on web pages. Preferrable this would be on a stand alone application. My specific question are on the logic. How do you tell the app to move the text? I understand it has to be threaded, but do you loop thru the drawString method a given number of time or what? I realize you'd need to the the x,y of the start of the text, but how do you move that, etc....
Ryan Headley<br /><a href="http://www.sudovi.com" target="_blank" rel="nofollow">http://www.sudovi.com</a>
With a textfield what I assume you would do would be to keep two copies of the string, one of which is the full string and the other is the current part of the string that is being displayed. The String class has a substring( int offset ) method that returns the string with the portion before the offest parameter chopped off... So in the thread you would assign the chopped off section of the original string to the displayed string, set the textfield with the displayed string, add some error checking to reset the displayed string if it is done, and there you have it!
Sorry about this post sounding so confusing... I could explain this alot better in code, but I thought you might like to write the code yourself...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Feb 25, 2001
What you can do is pretty simple, if the string you want to scroll is called scrollString then create a StringBuffer from it. Then call drawstring in a loop with scrollStringBuf as argument, after this. scrollStringBuf.deleteCharAt(0); scrollStringBuf.append(scrollString.charAt(0));