tags:

views:

1207

answers:

2

How can I make the text of a JLabel extend onto another line?

+5  A: 

You can do it by putting HTML in the code, so:

JFrame frame = new JFrame();
frame.setLayout(new GridLayout());
JLabel label = new JLabel("<html>First line<br>Second line</html>");
frame.add(label);
frame.pack();
frame.setVisible(true);
MrWiggles
I have two panel..how can I make the second panel appear to the next line ? e.g. lbl1 -- first line, lbl2 --- second line.JLabel lbl1 = new JLabel("Label 1:");panel.add(lbl1);JLabel lbl2 = new JLabel("Label 2");panel.add(lbl2);
Jessy
You could get some formatting issues if the default text style for labels does not match that of html. Although nine times out of ten it will work...
Tom Hawtin - tackline
For 2 panels below each other just use a GridLayout with 2 rows and 1 column. Easy peasy :)
MrWiggles
+1  A: 

Use two labels.

Tom Hawtin - tackline