开发者

Multi-lined Label in Scala

Short question, hopefully simple solution:

I've got my own renderer for a ListView, nothing too fancy, it just connects a 开发者_StackOverflow中文版Label and and Icon. My questions is, so far, the Label ignores my "\n"s. How can I change that? I'd like to have two lines for the information I present.

Thanks for listening.


Use html for your Label. Like this: new JLabel("<html>line 1<br>line 2</html>");


scala> import java.awt._
scala> import javax.swing._
scala> val frame = new JFrame()
scala> frame.setVisible(true)
scala> frame.setPreferredSize(new Dimension(400,300))
scala> val l = new JLabel("abc\nefg")
scala> frame.getContentPane.add(l)
scala> frame.pack
scala> l.setText("<html>abc<br>def</html>")

Using \n doesn't work, but <html>abc<br>def</html> does.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜