• 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

Dynamic JTable

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could you, please, tell me if there is any way to update (add a row) a JTable ? Something like addRow() ? Or a tip , link to some web page which gives a tutorial on it ?
I need it for a JDBC application.
Thank you very much.
Cata Lin.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JTable itself has no method for this - look instead to the TableModel which you have associated with the table. If you've used a DefaultTableModel, it has methods addRow() and insertRow() which should accomplish what you need. If you've used a Vector of Vectors instead of a TableModel, you can use the add() and insert() methods of Vector (be sure to create a new Vector to represent the row, since the table model is a Vector of Vectors). If you're creating your own class which implements TableModel, then it's up to you to provide a method to add/insert rows if you desire, depending on what sort of data structure you're using. (Note that the first two suggestions are likely easier.)
The Java Tutorial has a page here on how to use tables. I don't see any examples of adding / inserting rows there offhand, but they might be hiding. Good luck.
 
cata lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you, Jim, I used a DefaultTableModel in the end, and insert row was good because it updated the table automatically.
Many thanks.
Cata Lin.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic