• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Force the JList:Cellrenderer from another class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 =)
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
reply
    Bookmark Topic Watch Topic
  • New Topic