How to add and delete a row in a JTable.

C

C-man

Well I have a JTable set up with my own table model. Now how to I add, and
delete a row, or delete all rows and all that? Do I just make an addRow
function in my TableModel. If so, how do I make the function so that some
can call addRow(item1,item2,item3,item4...) and put an ambiguous amount of
items and have it add them to the columns that are in the table? Does that
make sense? Any help would be great.

Thanks
(e-mail address removed)
 
C

Chris Smith

C-man said:
Well I have a JTable set up with my own table model. Now how to I add, and
delete a row, or delete all rows and all that? Do I just make an addRow
function in my TableModel. If so, how do I make the function so that some
can call addRow(item1,item2,item3,item4...) and put an ambiguous amount of
items and have it add them to the columns that are in the table?

Yeah, sure, providing an addRow method is a fine idea, if it makes sense
for your model. As for how to do it, you first arrange for the model to
report the new information if asked (how you do this depends on how you
store the data for the table in your custom model; something we can't
possibly know), and then you fire an appropriate event. If you inherit
your custom model from AbstractTableModel (which you should...) then you
get a fireTableRowsInserted method that will fire the event for you, so
you just delegate that part to the superclass.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top