Newline in JLabel
How can I display a newline in JLabel ?
For example, if I wanted:
Hello World!
blahblahblah
This is what I have right now:
JLabel l = new JLabel("Hello World!nblahblahblah", SwingConstants.CENTER);
This is what is displayed:
Hello World!blahblahblah
Forgive me if this is a dumb question, I'm just learning some Swing basics...
围绕与所述串<html></html>并用破线<br/> 。
JLabel l = new JLabel("<html>Hello World!<br/>blahblahblah</html>", SwingConstants.CENTER);
You can try and do this:
myLabel.setText("<html>" + myString.replaceAll("<","<").replaceAll(">", ">").replaceAll("n", "<br/>") + "</html>")
The advantages of doing this are:
<br/> , without fail. < and > with < and > respectively, preventing some render havoc. What it does is:
"<html>" + adds an opening html tag at the beginning .replaceAll("<", "<").replaceAll(">", ">") escapes < and > for convenience .replaceAll("n", "<br/>") replaces all newlines by br (HTML line break) tags for what you wanted + "</html>" closes our html tag at the end. PS: I'm very sorry to wake up such an old post, but whatever, you have a reliable snippet for your Java!
You can use the MultilineLabel component in the Jide Open Source Components.
http://www.jidesoft.com/products/oss.htm
链接地址: http://www.djcxy.com/p/15682.html上一篇: 翡翠线断裂怎么样?
下一篇: JLabel的Newline
