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

Table Model and Table Cell Renderer

 
Veena Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Veena Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That's true..! They have implemented an Abstract Table Model internally..!
Thanks a lot ..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic