Microsoft KB Archive/251074

= Choice and Listbox controls no longer include type-ahead feature =

Article ID: 251074

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q251074



SYMPTOMS
After you upgrade the Microsoft virtual machine (VM) to build 31xx or later, the type-ahead behavior for the Java AWT Choice or Listbox control no longer works.



CAUSE
This feature was a side effect from the particular peer system that was used to implement the Java AWT control library at the time. Because the peer system changed in the Microsoft VM build 31xx, this feature did not carry over.



RESOLUTION
To work around this problem, you can implement this functionality in a sub-class of the Choice or Listbox control. The following code demonstrates how you can do this for the Choice control: import java.awt.event.KeyEvent;

public class ChoiceEx extends java.awt.Choice { public ChoiceEx { enableEvents(java.awt.AWTEvent.KEY_EVENT_MASK); } protected void processKeyEvent(KeyEvent ke) { int selectedIndex = this.getSelectedIndex; int itemCount = this.getItemCount; int key = ke.getKeyChar; for (int i = selectedIndex + 1; i < itemCount; i++) { char tmpc = Character.toLowerCase(getItem(i).charAt(0)); if (tmpc == key) { this.select(i); return; }   }    for (int i = 0; i <= selectedIndex; i++) { char tmpc = Character.toLowerCase(getItem(i).charAt(0)); if (tmpc == key) { this.select(i); return; }   }    super.processKeyEvent(ke); } }



MORE INFORMATION
The type-ahead feature allows users to type the first letter of an item in the Choice or Listbox control to make a selection. In Microsoft VM build 31xx or later, the user must use a mouse or the arrow keys to make a selection in the Listbox or Choice control.

