Microsoft KB Archive/251074

From BetaArchive Wiki
Knowledge Base

Article ID: 251074

Article Last Modified on 6/14/2006


  • Microsoft Java Virtual Machine

This article was previously published under Q251074


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.


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.


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() { 
  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) {;
    for (int i = 0; i <= selectedIndex; i++) { 
      char tmpc = Character.toLowerCase(getItem(i).charAt(0));
      if (tmpc == key) {;


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.


For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Additional query words: type first letter

Keywords: kbawtpkg kbprb KB251074