| Author |
Giving a Label a number
|
Steven Joost
Greenhorn
Joined: Sep 29, 2012
Posts: 28
|
|
Hello guys, I have a question, how can a JLabel get a number?
For example:
Sorry for my bad English, I'm german ;)
|
 |
Steven Joost
Greenhorn
Joined: Sep 29, 2012
Posts: 28
|
|
|
is there anything what I can use instead of .setText?
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 372
|
|
|
Format the number as a String using java.text.DecimalFormat and then use setText() .
|
 |
Steven Joost
Greenhorn
Joined: Sep 29, 2012
Posts: 28
|
|
can you give me a code example?
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 372
|
|
Mustermann Musterman wrote:
can you give me a code example?
Sorry - I assumed you could use Google.
http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
|
 |
Steven Joost
Greenhorn
Joined: Sep 29, 2012
Posts: 28
|
|
|
Er, ok got what I want.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Welcome to the Ranch
I would probably use String#format() myself, in preference to Decimal Format.
|
 |
Jón Jónsson
Greenhorn
Joined: Feb 20, 2009
Posts: 4
|
|
|
Or you could simply concatenate the number to an empty string
|
 |
 |
|
|
subject: Giving a Label a number
|
|
|