I cant believe fastest solution for a multilined JLabel is the following one (text comes from a var, and so I dont want to put HTML code manually every x chars, its so ugly):
public class JMultilineLabel extends JTextArea{
private static final long serialVersionUID = 1L;
public JMultilineLabel(String text){
super(text);
setEditable(false);
setCursor(null);
setOpaque(false);
setFocusable(false);
setFont(UIManager.getFont("Label.font"));
setWrapStyleWord(true);
setLineWrap(true);
}
}
… sure it isnt a better way to handle this????
If you want a multilne label then you simply use
HTMLin its text, as they support its use. Therefore, use line brake tag</br>to break lines or put separate lines in<p></p>paragraph tags.Do not forget to mark that you want to use HTML for a
JLabelby starting its text with the<html>tag.More available here.
BTW I forgot to check if there were other related questions about
JLabeluse and there were at least a few, check this or this. 🙂EDIT:
For a working sample, showing a different approach, without setting a style and with use of paragraph and label taking available space, please see below: