• Post Reply Bookmark Topic Watch Topic
  • New Topic

ListCellRenderer  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if someone could tell me what the advantages of a ListCellRenderer on a JList are besides changing the highlight color and adding an icon to each item in the list. Is it really worth anything more??
 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
You can create MyCellRenderer as below:
public class MyCellRenderer extends javax.swing.DefaultListCellRenderer {
...
public Component getListCellRenderer(...) {
...
}
}
In the getListCellRenderer method, you can change the hightlight color and set the icon. I think there is an example in SwingSet demo of JDK.
Good luck.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol, I already know that. My question was what OTHER advantages are there to a ListCellRenderer besides what you mentioned.
But thanks for replying.
Gregg
 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We are able to create a RichTextCellRenderer.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so maybe you can answer this for me. Why is it that when I remove an element from my ListModel, it has to re-render every single cell. It seems to slow way down when you have an icon in every cell.
 
Luong Nguyen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
JList only renders visible entries. Slow rendering depends on JVM and the number of entries. You should use VM1.2 or later. Please refer to the following URL for more information. http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html
Regards.
Luong
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!