Question

I have a problem with Java Swing JLabel. The text i want to display on the JLabel exceeds the bounds of the JLabel. I want to display it via a Marqueeeffect. I already implemented the effect but when there is a string that exceeds the bounds of the JLabel it gets cut off and the rest gets replaced with "...".

My question is, if there is any opportunity to set the textlength for a JLabel individually, not depending on the bounds, that it doesnt get cut off?

Hope somebody got an answer for me.

I dont use any LayoutManagers and i dont want the JLabel to get resized, it should only can contain text longer than the bounds of it.

Was it helpful?

Solution

I want to display it via a Marqueeeffect.

Check out the Marquee Panel.

OTHER TIPS

In this LayoutTest, you can see how the label's UI delegate uses layoutCompoundLabel() to elide the text when label's size falls below the preferred size.

In this MarqueeTest, MarqueePanel has a default FlowLayout, which adopts the display label's preferred size.

image

The Swing JLabel was not designed to do marquee scrolling.

Here's the source code for JLabel. You can modify the text handling routines to do a marquee scroll rather than compressing the text with an ellipsis.

Oh, you'd better use a layout manager. Your marquee JLabel won't layout correctly without a layout manager.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top