• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table model in swings  RSS feed

 
supriya acharya
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I want to add values in tabel..my code is




when i am trying to setvalue at position 5 or greater than that.it is hrowing exception arrayoutofbound. how can i add values now .
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a List<Object[]> instead of an Object[][], and add the row as an Object[] to the list. Do not forget to fire the right events, or your table won't see the changes. AbstractTableModel has methods called fireXXX for this.

If you to be able to add columns as well use a List<List<Object>>.


What is a better solution in this case is extend DefaultTableModel, and only override getColumnClass and isCellEditable. Then all the hard work is done for you. This is how I create 95% of my table models.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!