I have a JList
in which the displayed elements/objects can be disabled. A custom ListRenderer
greys them out. What I want to achieve is that list cells containing a disabled object can no longer be selected, they should be "dead".
Example:
1. Alice (enabled)
2. Cooper (disabled)
3. Rocks (enabled)
Let's assume the selected cell is "Alice". If I click on "Cooper", I don't want the selection to change. No ListSelectionEvent
should be fired, nothing should happen at all! If I navigate through the list using the cursor down
key, I want the "Cooper" cell to be skipped automatically. The next cell to be selected should be "Rocks". In short: I want the list to behave as if disabled elements simply were not present (but I need them to be displayed nevertheless).
I thought I might have to write my own ListSelectionModel
, but I don't see any reference to the elements in the list from there, so not sure how I could detect which objects are disabled and adjust the selection accordingly.
How can I achieve the described behavior?