| Author |
JTable, adding a row
|
Benjamin FAIVRE
Greenhorn
Joined: Mar 31, 2003
Posts: 8
|
|
I am bulding a JTable using my own TableModel. This TableModel extends AbstractTableModel. All is going well, except when I want to add a row at the end of the table. How can I implements such a method? Thanks for help! (and I want to keep extending AbstractTableModel, in order to implement some methodes that I need)
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Benjamin, This really should be in the Swing forum. But I'll give it a shot. I'm not real sure what you are asking here. But to add a row, you could just create an addRow() method to the model. Or you could do it thru a property change or even event. It really depends on your data structure that backs the model and the process by which you want to add data to the model. However you decide, you need to call fireTableDataChanged() or one of the other fireXXX() methods to let the table know that new data has been entered. Michael Morris
|
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
|
 |
Benjamin FAIVRE
Greenhorn
Joined: Mar 31, 2003
Posts: 8
|
|
Thanks for your reply! Finally I have decided to extend the DefaultTableModel because I have not found how to do! lol When I created an "addRow" methode in my model (extending the AbstractTableModel), I had a probleme with the data array : when I tried to extend it by adding a row, I get an error. My data array was defined with x row, and here, there was now y row, with y>x, so it was out of bounds. But I am not graduate from any Java High school (lol) so... I learn every hour and this is really interesting! Thanks again, take care
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
|
Moving to the Swing forum.
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
 |
|
|
subject: JTable, adding a row
|
|
|