• Post Reply Bookmark Topic Watch Topic
  • New Topic

Increase the number of rows  RSS feed

 
ankita sonal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can i construct a jtable in such a way that i specify just the, number of columns and coumn names and no row data....and later on how can i add any desired number of rows to the same jtable..
another doubt is that i want to add a few number of rows to an already existing jtable which has lesser number number of rows...how can i do that...??
ankita
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankita,
You need to construct a Data Model class that extends AbstractDataModel and holds the data in a Vector of Vectors.
- personally I prefer to write an object class that contains a vector of data and has get/set methods and some properties like name, id numbers, etc. If you do this you have to write the whole datamodel class to cater for those methods but the results are VERY flexible.
Then include your own addRows() method which inserts the new data into the data Vector at the correct place( you can have diff methods for replacing, inserting at row X and just adding to the end ).
Your add methods should add the data and, as the last step, call fireTableDataChanged() method to make the table get its data again
There are some examples in the Sun tutorial on DataModels. http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
Hope that helps.
Terry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!