2012-11-14 7 views
6

Ich verstehe, dass Sie eine neue Zeile mit <html> <br> </html> erstellen können, aber wenn ich dem Text eines Labels eine Variable (ist ein String-Typ) hinzufüge, funktioniert dieser Befehl nicht mehr.Wie man eine neue Zeile in einem JLabel mit Variablen hinzufügt

label.setText("blahblahblah" + variable + "<html><br>blahblahblah</html>");

Ich muss es Ausgabe:

blahblahblah
blahblahblah

Antwort

7

Sie müssen die <html> Tag als das erste, was in Ihrem String haben:

label.setText("<html>blahblahblah" + variable + "<br>blahblahblah</html>"); 
5

Es sollte sein:

label.setText("<html>blahblahblah" + variable + "<br>blahblahblah</html>");