• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question Regarding return DataInfo[] to Jtable

 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My search algorithm works find I am extending AbstractTabelModel
but the issue I always return an array size of recordCount which is 24 for our database but in the table model if i get my return DataInfo and code inputData.length;
always 24 but i need this to build the rows in my Jtable if I hardcode return 24 in the getRows() function it returns all records but I need to dynamically do this..
For example if my criteriaMatch() returns 5 records I pass this to the Jtable but the array size is 24 from recordCount() not 5 I need to get the number of records in the array to use my Jtable efficiently [dynamically]

Thanks Lisa
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you have rowData[][] in your abstractTableModel that takes care of the cell content. You can initially set it to nothing i.e. rowData[][] = {}; Whenever a query returns a certain number of records, you simply pass the information to abstractTableModel and dynamically allocate it. You can have something like: rowData = new[numofRecs][getColumnCount];
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rudy
Your close but let me explain a little better:::
criteriaFind()
{
DataInfo[] rv = new DataInfo[recordCount];//global always 24 records
.
.
.
.
if (found)
{
rv[counter] = new DataInfo(r, description, values);
counter++;
found = false;
//I tried this too
//Vector build = new Vector();
//build.addElement(new DataInfo(r, description, values);
}
}end of big forloop

//rv =(DataInfo[]) build.toArray(); //I get Object exception
return rv;
//it always returns array size 24 but 2 records find I want it to be array size 2 not 24,.
//My DataInfo[] rv = new DataInfo[recordCount];<--Always 24 when initialized.
}//end searchCriteria()

I would like to dynamically create the array size with records found,but as you see always 24 and i tryed setting it to null globally such as:
DataInfo rv = null;
It always returns null to the caller.....
Any help would be great for I have read vector api and Collections api
I am at a barrier now.
Thanks Lisa
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa,
The problem is why you always get 24. Is the number representing the total number of records in db.db? I think you should set recordCount to be the number of records that satisfy the search criteria.
Rudy
 
Debajyoti Pathak
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa,
a better idea would be to use a temporary vector to store the records found from search and then finally convert it into an array,.
Deb
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rudy
Deb,
I tryed to put into a vector and then called
criteriaFind()
{
DataInfo[] rv = new DataInfo[recordCount];//global always 24 records
Vector build = new Vector();
.
.
.
if (found)
{
rv[counter] = new DataInfo(r, description, values);
counter++;
found = false;
Vector build = new Vector();
build.addElement(new DataInfo(r, description, values);
}

//outside of forloop
rv =DataInfo[] vectorname.toArray();//heres my conversion to Array
return rv;

}
see above code when I do this the caller gets a
a jav.lang.Object exception runtime
and the record count still shows 24 at the caller??
I thought that the toArray makes the array = to the size of the vector.
ant ideas?
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sorry
build.addElement(new DataInfo(r, description, values));

forgot the closing paranthesis
 
Debajyoti Pathak
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do the conversion like this
rv = (DataInfo[]) vector.toArray(rv);
I hope it works.
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deb
It got rid of the error but I still see 24 for the returned array size.
I will investigate further.
Lisa
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa,
Can you show the part of the coding where you set the variable recordCount that you claim it always has a value of 24? You should investigate from that point.
Rudy
 
davidlong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lisa
I think you problem is too early declare your array size. try declare you array size after you vector get all elements like this:
DataInfo[] rv=null;//are you really need declare it here?
. //the code
.
.
build.addElement(new DataInfo(r, description, values);
}

//outside of forloop
DataInfo[] rv=new DataInfo[vectorName.size()];
//how about to declare it here?
rv =DataInfo[] vectorname.toArray();//heres my conversion to Array
return rv;
In this way, should solve your problem
Hope this will help.
David
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks very much David that solved the problem
Lisa
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks rudy deb david for your help with this hurdle.
Lisa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic