I know this is a late answer, but I just saw another question about a marquee that was closed because it was considered a duplicate of this answer.

So I thought I'd add my suggestion which takes a approach different from the other answers suggested here.

The MarqueePanel scrolls components on a panel not just text. So this allows you to take full advantage of any Swing component. A simple marquee can be used by adding a JLabel with text. A fancier marquee might use a JLabel with HTML so you can use different fonts and color for the text. You can even add a second component with an image.

I added links with actions to the marquee, but I can't get them to work. The mouse events don't go the right component, Sometimes they do, sometimes the don't.
–
user905374Jul 23 '13 at 14:22

@user905374, this is not supported. I have a version I played with a couple of years ago that does attempt to redispatch the mouse events to the proper component. Not sure how well it works. If you want to try this version then send me a message using the "Contact Us" page from the blog and I will send you this version.
–
camickrJul 23 '13 at 15:56

thank you for your answer, yes by examining the code I soon realized that this was not supported. I would like to try the other version, I sent you a message form the "Contact Us" page. Thanks.
–
user905374Jul 24 '13 at 6:20

Pls see in my answer below what I came up with
–
user905374Jul 24 '13 at 9:27

Basic answer is you draw your text / graphic into a bitmap and then implement a component that paints the bitmap offset by some amount. Usually marquees / tickers scroll left so the offset increases which means the bitmap is painted at -offset. Your component runs a timer that fires periodically, incrementing the offset and invalidating itself so it repaints.

Things like wrapping are a little more complex to deal with but fairly straightforward. If the offset exceeds the bitmap width you reset it back to 0. If the offset + component width > bitmap width you paint the remainder of the component starting from the beginning of the bitmap.

The key to a decent ticker is to make the scrolling as smooth and as flicker free as possible. Therefore it may be necessary to consider double buffering the result, first painting the scrolling bit into a bitmap and then rendering that in one go rather than painting straight into the screen.

Here is some code that I threw together to get you started. I normally would take the ActionListener code and put that in some sort of MarqueeController class to keep this logic separate from the panel, but that's a different question about organizing the MVC architecture, and in a simple enough class like this it may not be so important.

There are also various animation libraries that would help you do this, but I don't normally like to include libraries into projects only to solve one problem like this.

I'm still seeing problems: I'd expect MarqueePanel to extend JPanel, and tickAnimation() needs a return type. Also, start() and stop() need to see the Timer. Sorry if I sniped the question.
–
trashgodSep 1 '10 at 20:47

1

No problem. Lesson learned. Next time I'm going to dump a solution like this -- test it first. :)
–
Erick RobertsonSep 2 '10 at 11:40

This is supposed to be an improvement of @camickr MarqueePanel. Please see above.

To map mouse events to the specific components added to MarqueePanel

Override add(Component comp) of MarqueePanel in order to direct all mouse events of the components

An issue here is what do do with the MouseEvents fired from the individual components.
My approach is to remove the mouse listeners form the components added and let the MarqueePanel redirect the event to the correct component.