Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using carriage returns or newlines in a JLabel

Status
Not open for further replies.

gregmosu

Programmer
Jul 8, 2002
117
US
I am reading a name and date in from a database, and want each to display on its own line. How can I do this, newlines and carriage returns dont seem to be recognized. This is a little bit of code to help illustrate the problem..

//Reading info from DB and putting into a String
String text="";
while(rs.next()){
text+="Name: "+rs.getString("name")+"Date: "+rs.getString("date")+"\r\n";
}

//JLabel is called label
label.setText(text);

As you can see, I am trying to get each name and date combo to fit on its own line. Any help would be greatly appriciated.

-Greg
 
Jlabel's support HTML. Try doing this instead:

String text=&quot;<HTML>&quot;;
while(rs.next()){
text+=&quot;Name: &quot;+rs.getString(&quot;name&quot;)+&quot;Date: &quot;+rs.getString(&quot;date&quot;)+&quot;<BR>&quot;;
}
text = text + &quot;</HTML>&quot;;

//JLabel is called label
label.setText(text);

-gc
&quot;I don't look busy because I did it right the first time.&quot;
 
Thanks for the advice. It worked, but I ended up going with a scrolling panel because some of the text was getting cut off.... I'm not a very good swing programmer yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top