Java JLabel, break text to next line?

前端 未结 3 470
终归单人心
终归单人心 2021-01-11 23:27

It\'s been awhile since I asked a question!

I\'m developing an application in Java where JLabels are used. Anyway, as you may or may not be able to see

相关标签:
3条回答
  • 2021-01-11 23:53

    As I recall, you need to use a JTextArea if you want textwrap. JLabel doesn't do it.

    0 讨论(0)
  • 2021-01-12 00:05

    You can at StyledLabel component from JIDE Common Layer open source project at http://java.net/projects/jide-oss/.

    The problem with html JLabel approach is it doesn't auto-wrap and about 20 to 40 times slower than a plain JLabel.

    The problem with JTextArea or JTextPane approach is it has a weird size issue and is also 20 times slower.

    StyledLabel extends JLabel. Automatically line wrapping is just one of the many features it adds. And the performance is as fast as a plain JLabel.

    Hope it will help.

    0 讨论(0)
  • 2021-01-12 00:14

    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.

    If you want a component that can split the lines by itself, take a look at JTextArea.

    0 讨论(0)
提交回复
热议问题