File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Assigning floats to JLabels
jQuery in Action, 3rd edition