Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

programming question in GetValueAt method from AbstractTableModel  RSS feed

 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
in my getValueAt() method inside my AbstractTableModel, which displays the elements of my Jtable, I refer back to this same method getValueAt() to get the value of a different row or colomn...
Somebody at my work told me this was "recursive" programming and that it takes a lot of the heap if there are lots of rows because it calls the same method for every row inside the table...
Is this true or does this cause no problems ?
If it is what is the best way to do calculations with data that is inside a previous row or colomn?
Here's part of the code :

public Object getValueAt(int row, int column){

try {
case 0 : return String.valueOf(row+1);
case 1 :
String posStr = (getValueAt(row-1,5).toString());

pos = Integer.parseInt(posStr);
pos = pos + 1;
posStr = String.valueOf(pos);
return posStr;
}

Thanks,
Kristof
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kristof,
There should be no reason for you to perform the recursion. You have a handle on the data itself. Just use it. Your AbstractModel must have something holding the data, so you can just use it to be returned. For example:

Regards,
Manfred.
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Manfred,

No the items I need are not in my ArrayList they are simply calculations that happen when I fill the data...
So I cannot refer back to any sort of data.
In fact I have to look at what goes on inside my table to do the calculations so the recurence is very easy to use but I'm not sure if it's a good way or if there is any other way....
Kristof
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!