Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Giving a Label a number

 
Steven Joost
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anything what I can use instead of .setText?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Format the number as a String using java.text.DecimalFormat and then use setText() .
 
Steven Joost
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:Format the number as a String using java.text.DecimalFormat and then use setText() .


can you give me a code example?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mustermann Musterman wrote:
Richard Tookey wrote:Format the number as a String using java.text.DecimalFormat and then use setText() .


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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er, ok got what I want.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I would probably use String#format() myself, in preference to Decimal Format.
 
Jón Jónsson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could simply concatenate the number to an empty string
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic