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
2009-03-26 12:49:24
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
2009-03-26 12:56:06
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
2009-03-26 13:02:23
For 2 panels below each other just use a GridLayout with 2 rows and 1 column. Easy peasy :)
MrWiggles
2009-03-26 14:28:46