• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSpinner does not work for Numbers

 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please have a look at the following code to figure out why my customer JSpinner throws a runtime "java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer" error ?

>
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javadoc for the SpinnerNumberModel constructor you're calling says


All of the parameters must be mutually Comparable, value and stepSize must be instances of Integer Long, Float, or Double.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to create your own version of SpinnerNumberModel. Fortunately the source is available in the src.zip file inside your JDK folder.
 
ulvi ugur
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Guys,

I tried Ernest's path and used the constructor with Comparables but this time it started throwing casting exceptions about Byte and BigInteger which told me that I have to go either in the src from JDK or do my own stuff.

Thanks Rob, that was a good advice, generating another class for this feels a bit of an overkill but totally made sense compared to this "casting chaos".

Thanks and cheers,

Ulvi

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!