The renderer may look like a factory for returning components for the cells, but in fact it follows the flyweight rendering approach and uses the same component for rendering all the cells (each call to getListCellRendererComponent()
is supposed to reconfigure the same component instance for a specific cell and return it so that cell can be rendered).
That way, you can have JList
(as well as JTable
and JTree
) display massive amount of cells without having to instanciate components for each cell. As a side effect, the render component cannot respond to events, as it is only used during the render loop, but doesn't appear in the component tree.
Just as Neil Coffey said, you can add your listeners to the JList
(JTable
, JTree
) instead, and use the helper methods (locationToIndex(...)
, getCellBounds(...)
) to dispatch which cell was affected and thus deal with cell specific logic.