Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Assigning floats to JLabels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Assigning floats to JLabels" Watch "Assigning floats to JLabels" New topic

Assigning floats to JLabels

Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
If you have a JLabel that you wish to use for displaying the results of a calculation of two floats, what methods() are use for this?
Thanks, Dave.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
This is a job for java.text.NumberFormat or maybe java.text.DecimalFormat

SCJP2. Please Indent your code using UBB Code
Dave Johnson
Ranch Hand

Joined: May 25, 2003
Posts: 111
Thanks Jose.
The code I used was this: l[i].setText(""+tally[i]);
The I tried earlier was l[i].setText(+tally[i]); and obviously that was no good.
Anyway I'll read the stuff you suggested and thanks again mate.
rocket mass heater kickstarter
subject: Assigning floats to JLabels