public void setSelectedItem(Object item)
{
dataModel.setSelectedItem(item);
+ fireActionEvent();
}
/**
}
/**
- * This method hides combo box's popup whenever TAB key is pressed.
+ * This method is fired whenever a key is pressed with the combo box
+ * in focus
*
* @param e The KeyEvent indicating which key was pressed.
*/
{
if (e.getKeyCode() == KeyEvent.VK_TAB)
setPopupVisible(false);
- else if (keySelectionManager != null)
- {
- int i = keySelectionManager.selectionForKey(e.getKeyChar(),
- getModel());
- if (i >= 0)
- setSelectedIndex(i);
- else
- super.processKeyEvent(e);
- }
else
super.processKeyEvent(e);
}
*/
public KeySelectionManager getKeySelectionManager()
{
- return null;
+ return keySelectionManager;
}
/**
*/
protected KeySelectionManager createDefaultKeySelectionManager()
{
- return null;
+ return new DefaultKeySelectionManager();
}
/**
// Nothing to do here.
}
}
+
+ private class DefaultKeySelectionManager
+ implements KeySelectionManager
+ {
+
+ public int selectionForKey(char aKey, ComboBoxModel aModel)
+ {
+ int selectedIndex = getSelectedIndex();
+
+ // Start at currently selected item and iterate to end of list
+ for (int i = selectedIndex + 1; i < aModel.getSize(); i++)
+ {
+ String nextItem = aModel.getElementAt(i).toString();
+
+ if (nextItem.charAt(0) == aKey)
+ return i;
+ }
+
+ // Wrap to start of list if no match yet
+ for (int i = 0; i <= selectedIndex; i++)
+ {
+ String nextItem = aModel.getElementAt(i).toString();
+
+ if (nextItem.charAt(0) == aKey)
+ return i;
+ }
+
+ return - 1;
+ }
+ }
}