This discussion is archived
3 Replies Latest reply: Nov 21, 2008 11:06 PM by 843851 RSS

Scroll Text like Stock bar

843851 Newbie
Currently Being Moderated
hi guys,

i am new in javatv development and i am stuck a little in this issue

any one know how to scroll text on screen like the stock or news bar that we see on TV
i tried regular java code but it stopped the application cause the thread may be.


please can some one help or give hints i am using HText



thanks in advance
  • 1. Re: Scroll Text like Stock bar
    843851 Newbie
    Currently Being Moderated
    1. Create a component with a clip on the area in which you want the scrolling text to display.
    2. Get the width of the string you wish to scroll using FontMetrics.
    3. In the paint() and/or update() methods, use Graphics.drawString() to draw the string TWICE, once starting to the left of the component, and once at the right end of the first drawString() (using the width you got from FontMetrics). You draw twice to allow wraparound. With a very short string you might need to draw more than twice (if the string is narrower than your screen).
    4. Set a thread to redraw the two strings farther and farther left each time. When the first drawString() is no longer on screen, move the first draw back to start drawing at the left of your component. The user won't see this jump because the first and second strings being drawn are identical, so it appears that the same string is looping with a constant leftward motion.
    5. You may see flickering with each draw. If so, implement double buffering.
  • 2. Re: Scroll Text like Stock bar
    843851 Newbie
    Currently Being Moderated
    Also, if you wish to display icons, which some stock tickers display, you'll need to use something more complex than a simple drawString().
  • 3. Re: Scroll Text like Stock bar
    843851 Newbie
    Currently Being Moderated
    Thanks Imagist
    i will try to do it and i will give u the result

    thanks a lot