I want to do this:
JLabel myLabel = new JLabel();
myLabel.setText("This is\na multi-line string");
Currently this results in a label that displays
This isa multi-line string
I want it to do this instead:
This is
a multi-line string
Any suggestions?
Thank you
EDIT: Implemented solution
In body of method:
myLabel.setText(convertToMultiline("This is\na multi-line string"));
Helper method:
public static String convertToMultiline(String orig)
{
return "" + orig.replaceAll("\n", "
");
}
解决方案
You can use HTML in JLabels. To use it, your text has to start with .
Set your text to "This is
a multi-line string" and it should work.