Java JLabel,将文本分解为下一行? [英] Java JLabel, break text to next line?
问题描述
我问了一个问题已经有一段时间了!
It's been awhile since I asked a question!
我正在用Java开发一个应用程序 JLabels
使用。无论如何,正如您可能或可能无法从下面的图片中看到,类别测试
的文本被切断并最终说分类......而是
。一旦填满标签的宽度,我有什么方法可以打破文本?这是图像:
I'm developing an application in Java where JLabels
are used. Anyway, as you may or may not be able to see from the picture below, the text that says Category Test
gets cut off and ends up saying Categor...
instead. Is there any way that I can "break" the text once it fills up the width of the label? Here is the image:
我做了什么
我使用了像这样的JTextPane:
I used a JTextPane like so:
JTextPane text = new JTextPane();
SimpleAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER);
pane.add(text, c);
然后我添加了我的文字,但无论如何,谢谢!
Then I added my text, but thanks anyway!
推荐答案
JLabel
默认情况下无法执行此操作。但是 JLabel
s对html有一些支持,所以 JLabel
包含文本< html> ;第一行< br />第二行< / html>
将显示在两行上。
JLabel
s can't do that by default. But JLabel
s have some support for html, so a JLabel
with the text <html>First Line<br />Second Line</html>
would show up on two lines.
如果你想要一个可以的组件将这些行分开,看看 JTextArea
。
If you want a component that can split the lines by itself, take a look at JTextArea
.
这篇关于Java JLabel,将文本分解为下一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!