Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove comma in the JSpinner

 
Swaranga Sarma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15439
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swaranga Sarma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic