Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic JTable

 
cata lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic