Computer Science Canada

Appending rows to the end of a JTable

Author:  Hikaru79 [ Sun Dec 12, 2004 6:30 pm ]
Post subject:  Appending rows to the end of a JTable

I'm busy working on the infamous Database java project. I decided to go with Swing for it, and most of it has been rather smooth. However, I do have this hiccup. I have a JTable that takes the 2d array I generate and displays it. The user has the choice to add fields to the database either from file or manually. The values get added to the array no problem. here's where the catch is-- I have the updated array, but how to update the table with it? I've gotten it working so far by simply creating a NEW table with the NEW array and adding it to a NEW JScrollPane. However, this is probably horribly inefficent and there has to be a way to simply have the JTable check the array it was passed again, and redraw itself. Can anyone give some example code of this working out? ATM, it's going way too slow for comfort =/

Thanks! Very Happy Any and all help greatly appreciated!

Author:  TheZsterBunny [ Sun Dec 12, 2004 9:41 pm ]
Post subject: 

lolololol

Hikaru, I've hit the same problem, and after smashing my head against it for the better part of 6 hours this morning, I've just decided to switch to a 'dos like' interface.

However, I have a book to 'lend' you if you so desire.

-Z

Author:  Martin [ Tue Dec 14, 2004 3:40 pm ]
Post subject: 

Why not just use a tree?

Author:  TheZsterBunny [ Fri Jan 07, 2005 5:33 pm ]
Post subject: 

coz trees are plants. duh! we want code.

Rolling Eyes

-Z

Author:  rizzix [ Fri Jan 07, 2005 6:45 pm ]
Post subject: 

hmm y dont u clean up the table contents and re-fill it with new values ( a new array). this is a good alternative.

but still inefficient.. the most efficient method is to update the Vector the table uses and the contents of the JTable right away. that is simply input a new record at so-and-so position in the Vector the in the respective position in the JTable etc likewise.

EDIT: to do this you might want to use the DefaultTableModel as opposed to an array.


: