aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Remove comma in the JSpinner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Remove comma in the JSpinner" Watch "Remove comma in the JSpinner" New topic
Author

Remove comma in the JSpinner

Swaranga Sarma
Greenhorn

Joined: Dec 17, 2010
Posts: 9
Hello,

Is there a way that I can remove the commas in a JSpinner. Can I remove the default number editor and implement my own?
Swaranga Sarma
Greenhorn

Joined: Dec 17, 2010
Posts: 9
I tried the following :



But when I tried to change the value of the spinner, it threw me a ClassCastException :


Please help.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14270
    
  21

Why are you using Longs instead of Integers? Do you understand what the error message means:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long

It means that the program is trying to cast an Integer object to a Long object, but that doesn't work. Try using Integer instead of Long.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Swaranga Sarma
Greenhorn

Joined: Dec 17, 2010
Posts: 9
I need the model to use Long, because the spinner represents the size of a file in bytes. If the file size in more than 2 GB then the corresponding value in bytes will be more that Integer.MAX_VALUE.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Set the model first, then the editor. Apparently, by setting the editor first you give the spinner an Integer value. This is then somehow not overwritten when you set the model. I simply swapped these two lines and the errors disappeared.

And do you really need so many zeros? Wouldn't a simple "0" be good enough? This will already remove the comma but only display as many digits as necessary.

Oh, and I'll move this thread to our GUI forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Remove comma in the JSpinner