Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Force the JList:Cellrenderer from another class  RSS feed

 
B Chapel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there !

I'm working with two different JFrame, one with a JSlider, and an another one with a JList. The JList cells implement my own ListCellRenderer<> and the method getListCellRendererComponent(...) which is called when I scroll the JList, select an element, DnDrop or any other actions on the JList.
I want the JList to update (the ListCellRenderer) when I also do an action on my JSlider... But I can't find anything that actually work as I want...
I did look at firePropertyChange but I have no idea how I should implement it !

I hope you have anything to help me !
Thank you =)
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure exactly what you are asking, but it sounds like you are trying to force your JList to re-render its cells.

The easiest is probably to simply call yourList.repaint(), or to be more forceful, call yourList.setUI(yourList.getUI()).

You really want to call the AbstractListModel's fireContentsChanged() method, but that method is protected, so you would have to create a custom subclass of AbstractListModel in order to call it.
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by saying you want the list to update when you do an action on the slider? Do you mean you want the slider to control the position of the list's scrollbar? Or do you want the list to be rendered differently (font, color, etc.) based on the slider's value?
 
B Chapel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I want to re-render the cells (color in fact) of the Jlist !
I will try the repaint / setUI

Edit : ok I found a way to update the render but it's not really clean... I just set a value to the 0 index with the value of this index, which will do the render job (because the JList has changed) and properly update the color of my JList :
list.set(0,list.get(0)); // indirectly call the getListCellRendererComponent of my class implementing the ListCellRenderer.

The repaint and setUI don't work at all...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!