Microsoft KB Archive/251074: Difference between revisions
(importing KB archive) |
m (Text replacement - "<" to "<") |
||
Line 69: | Line 69: | ||
int itemCount = this.getItemCount(); | int itemCount = this.getItemCount(); | ||
int key = ke.getKeyChar(); | int key = ke.getKeyChar(); | ||
for (int i = selectedIndex + 1; i | for (int i = selectedIndex + 1; i < itemCount; i++) { | ||
char tmpc = Character.toLowerCase(getItem(i).charAt(0)); | char tmpc = Character.toLowerCase(getItem(i).charAt(0)); | ||
if (tmpc == key) { | if (tmpc == key) { | ||
Line 76: | Line 76: | ||
} | } | ||
} | } | ||
for (int i = 0; i | for (int i = 0; i <= selectedIndex; i++) { | ||
char tmpc = Character.toLowerCase(getItem(i).charAt(0)); | char tmpc = Character.toLowerCase(getItem(i).charAt(0)); | ||
if (tmpc == key) { | if (tmpc == key) { |
Latest revision as of 08:00, 21 July 2020
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.
REFERENCES
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