• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding rows in JTable  RSS feed

 
Naveen Asha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I am using a JTable with AbstractTableModel, it query the database and load all data. I can easily edit/save changes in the database through 'update/set' query.
But I want to add new rows in the database through JTable. For this reason JTable should give 5-10 blank rows and user can enter new data directly in these rows and save to database.
Any one know how to do it, please help me!
Naveen
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naveen,
This is just a suggestion (since it's a bit difficult for me to help you without seeing your code), but the "javax.swing.table.DefaultTableModel" has methods for adding rows to a "JTable". Have you tried looking at its source code? Perhaps it will help you?
Basically, the "JTable" 'listens' to its "TableModel". The "getRowCount()" method returns the number of rows that should be in the "JTable", so in order to display an extra 5 rows, you would have to make that method return the desired (total) number of rows.
The "getValueAt()" method returns the value to be displayed by the "JTable" in a particular cell, so in order to display a "blank" cell, you would have to make that method return something appropriate (like an empty "String", maybe).
Again, without seeing your code (and being too lazy to offer you my own), there's not much else I can offer.
Hope this has helped you, anyway.
Good Luck,
Avi.
 
Fahad Hasan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
use DefaultTableModel, in which u have AddRow() method..... u have 2 write and read DefaultTableFormat code in order to check its working...beside that why don't u search for Java Swing Boook i m sure u'll find DefaultTableFormat example overthere....
If u face any difficulty i can mail u my code but u should try first then go for the code atleast 2 get an idea of what DefaultTableModel is..?
Take care and i'll do the rest...
:roll:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!