• Post Reply Bookmark Topic Watch Topic
  • New Topic

extracting an integer value from a JTable(sounds so easy :S)  RSS feed

 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone.
I am aware that this seems liek such a simple task, but its really not working for me.
I know that the JTable method valueAt(int row, int col) returns an object, so i figure why not just cast that object to an Integer, then once its cast extract the integer value of that Integer by calling intValue() on it.
This is what it looks like, and compiles.


and incase your wondering when i look inside my Jtable when it is running the value at (0,5) is infact an integer, that being the number 8.So i am quite stumped.

Any ideas would be much appreciated
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry once again forgot to mention something.
I am currently using this as a solution so my program GUI runs, but its seems kind of rediculous.
String str=((String)negotiationTable.getValueAt(0,5));
int val=Integer.parseInt(str);
,then again what do i know, maybe it is the only solution. :S
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking out loud and new at Swing, so sorry if I send you down the wrong path, but what if you overload the getValueAt() method in the TableModel?

in a class I have called CustomTableModel I have the method getValueAt() that returns Object

what if, in addition you had

A difference in return type only is not sufficient to constitute an overload and is illegal.

[ January 21, 2005: Message edited by: Tim McGuire ]
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi tim,
Im also prety new at swing, and i havnt yet devled into the world of creating my own table model etc, even thought it seems simple.But it isnt my main conern right now for finishing my cureent project so i think im just going to stick with my possibly inefficient way of doing it.Thanks though!
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you create the table and it's data?

Did you put an [integer] 8 in that column or a [String] "8"?
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jeff,

I created the tables data from parsing an xml file, and putting the parsed information into a vector, and yes i just realized i was putting every object in the vector as a string when clearly i dont have to, stupid mistake i'll change it to an int, so when i do the cast from object to int it should work.Thanks for the idea.
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No wait im an idiot

When im doing the parsing of the XML file, i forgot that i have to use a method called getTextTrim to get the value from a child in the xml file, so i infact have to put it in a string, thats why i didnt make it an int inthe first place...hahah oh well sall gravy.

The programmer after me can work on effiency, im just here to build a prototype
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!