• Post Reply Bookmark Topic Watch Topic
  • New Topic

preventing selection in JList

 
Rob Byrd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a JList in which certain items throughout the list should not be selectable. To do this, I've subclassed ListCellRenderer and in the hasFocus method I clear the list selection on those items that should not be selectable. This works, except that the selection background color appears for a split second and is quite visible for the moment it appears. Is there a way to prevent this behavior?
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Byrd:
I'm trying to create a JList in which certain items throughout the list should not be selectable. To do this, I've subclassed ListCellRenderer and in the hasFocus method I clear the list selection on those items that should not be selectable. This works, except that the selection background color appears for a split second and is quite visible for the moment it appears. Is there a way to prevent this behavior?


It seems to me you should be subclassing DefaultListSelectionModel,
not ListCellRenderer. By messing with the renderer you can change
the appearance of a selected cell, but can't prevent it from being
selected in the first place.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!