aspose file tools*
The moose likes Beginning Java and the fly likes Scrollers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scrollers" Watch "Scrollers" New topic
Author

Scrollers

ryan headley
Ranch Hand

Joined: Jun 28, 2000
Posts: 156
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>
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
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));
 
Consider Paul's rocket mass heater.
 
subject: Scrollers