Java JLabel,将文本分解为下一行? [英] Java JLabel, break text to next line?

查看:153
本文介绍了Java JLabel,将文本分解为下一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了一个问题已经有一段时间了!

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> 将显示在两行上。

JLabels can't do that by default. But JLabels 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆