aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Table Model and Table Cell Renderer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Table Model and Table Cell Renderer" Watch "Table Model and Table Cell Renderer" New topic
Author

Table Model and Table Cell Renderer

Veena Nair
Greenhorn

Joined: Jul 08, 2012
Posts: 13
Hello..
I just have started working with Swing. And have tried quite a large number of examples. But i still am not able to make out the difference between working with "Tables", "Table Model" & "Table Cell Renderer".
Can anyone please tell me the differences between these three and when exactly to use them ?
Thanks in advance.
Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
Veena,
Table is an independent component created using Table Model and Table Cell renderer. In swing, every component is divided into 2 parts.
1 is model and other is view. Table Model store the data which you need to display on your table object. Table Cell renderer stores the
presentation related information and decides how your data should get displayed on UI.


Regards,
Mahesh Kedari - Fidus Technologies Ltd.
Veena Nair
Greenhorn

Joined: Jul 08, 2012
Posts: 13
first of all thanks for considering my qustion..!
But there are situations where we need not want to use either of these to create a Table.. i mean even without a table model.

String data[][] = {{"John","BCA","A"},{"Russel","MCA","b"},
{"Michael","MBA","c"},{"Frieda","BCA","d"}};

String col[] = {"Name","Course","Grade"};
JTable table = new JTable(data,col);

Veena Nair
Greenhorn

Joined: Jul 08, 2012
Posts: 13
So how do you kno when to use Table Model??? Also i get confused in situations like the following....
Few methods we call on Table, whereas similar ones on TableModel. Exa:
If TableModel is the one which handles table DATA , then why we call methods directly on Table ???
Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
Looks like you are confused a bit with some specific example. I would suggest you to please go through the constructor of your example

When you call this parametrized constructor, it internally creates an object of TableModel for you and puts your "data" and "col" inside it.
JTable cannot be constructed without TableModel. Im not sure if there is a trick to create it, but that wont be of any use as far as i know.
Experts, please comment.
Veena Nair
Greenhorn

Joined: Jul 08, 2012
Posts: 13
Yes. That's true..! They have implemented an Abstract Table Model internally..!
Thanks a lot ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table Model and Table Cell Renderer