Multi-lined Label in Scala

542 views Asked by At

Short question, hopefully simple solution:

I've got my own renderer for a ListView, nothing too fancy, it just connects a 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.

2

There are 2 answers

4
Costis Aivalis On

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

0
ziggystar On
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.