简体   繁体   English

Java Swing JLabel文本长于界限

[英]Java Swing JLabel Text longer than bounds

I have a problem with Java Swing JLabel. 我对Java Swing JLabel有问题。 The text i want to display on the JLabel exceeds the bounds of the JLabel. 我要在JLabel上显示的文本超出了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 "...". 我已经实现了该效果,但是当存在超出JLabel范围的字符串时,它将被切断,其余的将被替换为“ ...”。

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? 我的问题是,是否有机会单独设置JLabel的文本长度,而不取决于范围,所以它不会被截断吗?

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. 我不使用任何LayoutManagers,也不想调整JLabel的大小,它只能包含比其边界更长的文本。

I want to display it via a Marqueeeffect. 我想通过字幕效果显示它。

Check out the Marquee Panel . 查看“ 字幕面板”

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. 在此LayoutTest ,您可以看到标签的UI委托如何在标签的大小降至所需大小以下时使用layoutCompoundLabel()拉出文本。

In this MarqueeTest , MarqueePanel has a default FlowLayout , which adopts the display label's preferred size. 在此MarqueeTestMarqueePanel具有默认的FlowLayout ,它采用了显示标签的首选大小。

图片

The Swing JLabel was not designed to do marquee scrolling. Swing JLabel并非旨在进行字幕滚动。

Here's the source code for JLabel. 这是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. 没有布局管理器,您的选取框JLabel将无法正确布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM