File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes extracting an integer value from a JTable(sounds so easy :S) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "extracting an integer value from a JTable(sounds so easy :S)" Watch "extracting an integer value from a JTable(sounds so easy :S)" New topic
Author

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

luc comeau
Ranch Hand

Joined: Jan 20, 2005
Posts: 97
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


National Research Council<br />Internet Logic Department
luc comeau
Ranch Hand

Joined: Jan 20, 2005
Posts: 97
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

Joined: Apr 30, 2003
Posts: 819

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

Joined: Jan 20, 2005
Posts: 97
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

Joined: Sep 29, 2004
Posts: 113
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

Joined: Jan 20, 2005
Posts: 97
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

Joined: Jan 20, 2005
Posts: 97
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extracting an integer value from a JTable(sounds so easy :S)
 
Similar Threads
JTable
JTable
JTable
JCombobox in JTable and lookup values
JTable Trouble