Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

multipling cells in jTables

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and what seems to be the problem?
 
Jamie Wool
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic