aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes TableModel Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "TableModel Question" Watch "TableModel Question" New topic
Author

TableModel Question

Ravikiran Choppalli
Ranch Hand

Joined: Nov 18, 2000
Posts: 49
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.


Thanks,<BR>Ravikiran<BR>rkchoppalli@yahoo.com
Aleksey Matiychenko
Ranch Hand

Joined: Apr 03, 2001
Posts: 178
have a function:
public boolean isCellEditable(int row, int col)
{
return false;
}
Ravikiran Choppalli
Ranch Hand

Joined: Nov 18, 2000
Posts: 49
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

Joined: Apr 03, 2001
Posts: 178
You have to create your own TableModel.
Ravikiran Choppalli
Ranch Hand

Joined: Nov 18, 2000
Posts: 49
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

Joined: Oct 19, 2000
Posts: 28
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

Joined: Nov 18, 2000
Posts: 49
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TableModel Question