• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable, adding a row

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Benjamin FAIVRE
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic