Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Object to Integer

  Asked By: Clifton    Date: Jan 28    Category: Java    Views: 2163
  

how can I cast a jSpinner.getValue() to an integer, I tried a straight
cast but the compiler says types are not compatible.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Fabiola Ferrrari     Answered On: Jan 28

Are you casting to int or Integer?

you cannot cast  to an int, as it is a primitive and
not a subclass of Object.

If you want to save the value as an int, use the
following:
((Integer)(s.getValue())).intValue();

 
Answer #2    Answered By: Edith Mcdonald     Answered On: Jan 28

u may try this one also

Integer.parseInt(myJSpinner.getValue().toString().trim());

 
Answer #3    Answered By: Blas Fischer     Answered On: Jan 28

from sun swing tutorial "uiswing\components\spinner.html"

Object getValue()

Set or get the currently displayed element of the sequence.

Set or get the current Date for this sequence.
----------------

SpinnerListModel

A spinner model whose values are defined by an array of
objects or a List. SpinnerDemo's Month spinner uses this
model, initialized with an array derived from the value
returned by the getMonths method of java.text.DateFormatSymbols.

SpinnerNumberModel

Supports sequences of numbers, which can be expressed as
doubles, ints, or Numbers. You can specify the minimum and
maximum allowable values, as well as the step size — the
amount of each increment or decrement. The Year spinner uses
this model, created with the following code:

SpinnerModel model =
new SpinnerNumberModel(currentYear, //initial value
currentYear - 100, //min
currentYear + 100, //max
1); //step

 
Answer #4    Answered By: Tara Ryan     Answered On: Jan 28

which type does jSpinner.getValue() return?
if jSpinner.getValue() returns with a String value u should write Integer
variable=Integer.parseInt(jSpinner.getValue()) ...
this is just for String...

 
Didn't find what you were looking for? Find more on Object to Integer Or get search suggestion and latest updates.




Tagged: