• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in understanding Swing concepts: Renderers,Editors and Model

 
Prashant Langade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I am a newbie to Swing. However i need to understand the following concepts from swing.

Renderers,Editors and Model

I have already couple of times gone through the link from oracle. http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

But i am finding it bit difficult to understand it programatically(how the things work).

Can any one help me with any other links/pdf's which are simple to understand for these three concepts?

Thanks
Prashant
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider a JTable. It is the "View" component and as such is not aware of any data. It totally relies on the underlying TableModel for the data. Whenever it needs to display any data, it will ask the model internally using the TableModel#getValueAt(int row, int column) Notice this method returns an Object and as such is "raw" data. The table then needs to figure out how to display (or render) it. For this it internally uses the TableModel#getColumnClass()
Now the table has the raw data as well as its class. Then the table will try and decide how to display it using these two values. The default JTable has some built in renderers (e.g. Boolean.class returned from getColumnClass will be rendered as a JCheckBox)
In addition to this, you can provide your own renderers (e.g. if getColumnClass() returns Color.class then the renderer will be a JLabel, colored in that particular color)
If no renderers are found (built in + your custom) then the table will default to plain text (using the value getValueAt().toString()).

Of course this is an over simplified conceptual explanation. If you got any further specific questions, do feel free to ask!
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i am finding it bit difficult to understand it programatically(how the things work).


Then ask a specific question about what you find confusing. We are not mind readers. We can't guess what you find confusing.

The tutorial includes working examples that you can download and play with. What part of the code do you not understand? If we know that then maybe we can answer your question.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic