File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1081
    
  10

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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1081
    
  10

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: 39755
    
  28
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Giving a Label a number