This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scrollers" Watch "Scrollers" New topic


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="" target="_blank" rel="nofollow"></a>
Nathan Pruett

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


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.
I agree. Here's the link:
subject: Scrollers