This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Giving a Label a number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Giving a Label a number" Watch "Giving a Label a number" New topic
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
Bartender

Joined: Aug 27, 2012
Posts: 1166
    
  17

Format the number as a String using java.text.DecimalFormat and then use setText() .
Steven Joost
Greenhorn

Joined: Sep 29, 2012
Posts: 28
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

Joined: Aug 27, 2012
Posts: 1166
    
  17

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

Joined: Sep 29, 2012
Posts: 28
Er, ok got what I want.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43995
    
  33
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: 5
Or you could simply concatenate the number to an empty string
 
Have you checked out Aspose?
 
subject: Giving a Label a number
 
It's not a secret anymore!