Re: Two Questions: JSpinner and datatype
On Mon, 17 May 2010 12:37:27 +0000 (UTC), Rhino
<no.offline.contact.please@example.com> wrote, quoted or indirectly
quoted someone who said :
1. If I create a JSpinner with a SpinnerNumberModel and specify the numbers
in the model explicitly as short, why can't I rely on the getValue() from
the JSpinner always returning shorts? In other words, if I define it all
with shorts, what actions on my part will result in getValue() returning an
Integer or something other than Short? For some reason, the results from
getValue() are sometimes Short but sometimes Integer and I don't understand
why. I'm trying to figure out how to make getValue() return ONLY Short (or,
failing that, to return only Integer.) This is the statement that defined
the model:
Here is the code for SpinnerNumberModel.setValue
public void setValue(Object value) {
if ((value == null) || !(value instanceof Number)) {
throw new IllegalArgumentException("illegal value");
}
if (!value.equals(this.value)) {
this.value = (Number)value;
fireStateChanged();
}
Note how it accepts any sort of Number, e.g. Short, Integer, Float,
Long ... and uses that for the internal representation. What ever you
put in will be what you get back out.
}
--
Roedy Green Canadian Mind Products
http://mindprod.com
Beauty is our business.
~ Edsger Wybe Dijkstra (born: 1930-05-11 died: 2002-08-06 at age: 72)
Referring to computer science.