File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Remove comma in the JSpinner" Watch "Remove comma in the JSpinner" New topic

Remove comma in the JSpinner

Swaranga Sarma

Joined: Dec 17, 2010
Posts: 12

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

Joined: Dec 17, 2010
Posts: 12
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: 15101

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

Joined: Dec 17, 2010
Posts: 12
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

Joined: Oct 27, 2005
Posts: 20279

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Remove comma in the JSpinner
It's not a secret anymore!