aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Dynamic JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamic JTable" Watch "Dynamic JTable" New topic
Author

Dynamic JTable

cata lin
Ranch Hand

Joined: May 11, 2000
Posts: 44
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
cata lin
Ranch Hand

Joined: May 11, 2000
Posts: 44
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic JTable