I have a JList that will point to a selected JList depending on user. It acts like a monitor that will monitor the selected JList. When I implements custom cell renderer and programmically do something like this.list = getSelectedList(), the cell renderer does not react to this sudden change of information. How do I notify the JList to reevaluate its list data without having to invoke add/remove function?
I have a JList that will point to a selected JList depending on user.
Share
this.list = getSelectedList()affects another JList object to thethis.listfield. If you set a custom renderer tothis.listbefore executing this line, you set the renderer on another JList object, and there is no way that the renderer becomes magically attached to the new selected list.You’re confusing variables and objects. When you call a method on the object, you’re modifying the object the variable points to, and not the variable itself. If you want to attach the same cell renderer to the newly selected JList, you need the following code: