Re: a JList feature

Diego  found a feature (a bug?) in Swing's JList: it processes keystrokes to assist with keyboard navigation. As I discovered, JComboBox behaves similarly. 

Keyboard navigation in itself is not bad; it's Diego's unique setting that makes it problematic. First, he seemed to have a huge list of entries and hitting a key pulls thousands of objects from the database. Second, that happened when he hit the Del key. The implementation of JList is obviously not optimal:

The mechanism in JComboBox is cleaner: for keyboard navigation one supplies a JComboBox.KeySelectionManager, which hides the navigation logic (the default implementation evaluates only one keystroke).

That JList and JComboBox implement the same feature using different mechanisms is a bit puzzling. Especially if you know that JComboBox uses a JList internally. One thing is scary, though. The JList instance used inside JComboBox's UI delegate still has the it's own KeyListener for navigation. The only way to remove it, is to inherit from BasicComboBoxUI, overwrite createList() and use Diego's trick.

I still find that keyboard navigation is a feature not a bug. Diego complains that this functionality is too dependent of the storage mechanism. In my opinion independence of the storage mechanism is provides by the means of ListModel. Combine that with JComboBox's KeySelectionManager and you have a pretty generic and easily customizable solution. JList's implementation is stupid, I agree with that.

Sun, 11 Jul 2004, 21:15 | Java | PermaLink
« Desktop-based Bug Tracking Software | Home | Back From The Death »