Java jlabel, break text to the next line?
•
Java
It's been a while, because I asked a question!
I am developing an application using jlabels in Java In any case, as shown in the figure below, you may not see or may not be able to see. The text of the category test is truncated and will eventually say category Is there any way I can "break" the text once it fills the width of the label? This is the image:
What did I do?
I used jtextpane:
JTextPane text = new JTextPane(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr,StyleConstants.ALIGN_CENTER); pane.add(text,c);
Then I added my text, but anyway!
Solution
Jlabel cannot do this by default However, jlabels has some support for HTML, so the text of jlabel is < HTML > first line < br / > second line < / HTML > and two lines will appear
If you want a component that can split rows by itself, check jtextarea
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码