• Post Reply Bookmark Topic Watch Topic
  • New Topic

multipling cells in jTables

 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Basically i want to multiply two cells in a single jTable and place the result in a third cell. In this case one cell is a float and the other is an int, the result needs to be a float.

My rubbish bit of code

 
Sebastiaan Kortleven
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and what seems to be the problem?
 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with the above code i get the error

FrontEnd/front.java [2,490:1] inconvertible types
found : java.lang.String
required: java.lang.Float
saleSalesCheckoutTable.setValueAt((salesQuantityTextField.getText() * (Float)salesQuantityTextField.getText()),0,4) ;

Which pretty much points out that my types are mismathcing, but i've tried lots of different combinations and don't seem to be able to extract anything other than a string out of the cell values.
 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i also tried striping the code down into stages, in this case simply attemtping to extract an integer from a table cell

int value = myTable.getValueAt(i,2);

but get

FrontEnd/front.java [2,491:1] incompatible types
found : java.lang.Object
required: int
int value = myTable.getValueAt(i,2);
^
1 error
Errors compiling front.
 
sasi kala
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
First convert the values into required data types and then set the product to table.

Object to premitive datatypes,

Integer in = new Integer(table.getValueAt(0,3).toString());
int value = in.intValue();

Hope this helps you.

All The Best.
 
brijesh sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we do .getText() we get string , so convert the string to integer by using Interger constructor . or try parseInt(string s).
hope this might help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!