Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a Object to an Integer

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
I want to get a value from a JTable, which I get from this

call_var = event_model.getValueAt(row, col);

then set the value at the desired location and subtract the value by 1;

I think I need to cast the object to integer and subtract the value by 1 and place back into the table.

What am I missing in this code segemnt? event_model.setValueAt((new Integer(call_var - 1)), row, col);

repeat code --

int row = 0;
int col = 16;
Object call_var;
call_var = event_model.getValueAt(row, col);
// call_var = 2
event_model.setValueAt((new Integer(call_var - 1)), row, col);
// need to set the value to 1

Dano
dskryzer@hotmail.com
What's your major malfunction
 
Dano,

It depends on what 'type' the Object is that you put in there. Say you put a 'String' type in there, then you would use Integer.parseInt() to make an 'int' from the string.

Hope this helps
-pete
 
Where would I place the Integer.parseInt()?

So I would change the statement to
From -
event_model.setValueAt((new Integer(call_var - 1)), row, col);
To -
event_model.setValueAt((new Integer.parseInt(call_var)-1) call_var, row, col);

Dano
dskryzer@hotmail.com
What's your major malfunction
 
Dano,

Yeah sort of... I guess. I would ususally spread the code out until I get it working, i.e.:


// if call_var is a String object
int oldVal = Integer.parseInt(call_val);
// put the same 'type' back into the cell
event_model.setValueAt( Integer.toString( oldVal - 1));


Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top