Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TableModel Question

 
Ravikiran Choppalli
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm using DefaultTableModel to display my Data in the table format in the GUI. Now, How can I make the cells non-editable ?
Thanks,
Ravi.
 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a function:
public boolean isCellEditable(int row, int col)
{
return false;
}
 
Ravikiran Choppalli
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aleksey,
Thanks for the reply. But, where shall I define this ? Do I need to create my own table model extending DefaultTableModel and override the function or can I just write this function in the main gui class where i'm using the table.
Thanks,
Ravi.
 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to create your own TableModel.
 
Ravikiran Choppalli
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How much better is it to use extend the AbstractTableModel instead of DefaultTable model. Could you help me understand what you get the difference b/w these two?
Thanks,
Ravi.
 
Emerson Dunne
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DefaultTableModel manages the row data in a Vector of Vectors. It is generally accepted that the DefaultTableModel is a good choice for small to medium size Models, particularly where data will be added and removed after the model's construction.
If your model gets large, the Vector of Vectors can have performance problems.
One of the primary advantages of creating your own custom table model is the ability to leave your data in its native form... in the case of FBN, this might be a DataInfo array. To create your own custom table model by extending AbstractTableModel, you simply add a few (3, I think) data accessor methods. If you don't plan on adding and removing rows after your model is constructed then a Custom Model is a great approach.
BTW, in the "real world", I think most Swing applications that use JTables use custom models.
 
Ravikiran Choppalli
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emmerson,
Thanks for your explanation.
As you said, since we're not changing (adding/deleting) rows from the model, custom model would be fine. Actually i've already implemented using default model. I'll try to change it and see. (Only problem with this is that isCellEditable() always returns true )
Thanks,
Ravi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic