• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to implement key selectable Choice list ?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using java.awt.Choice to display all the states in US, Canada and Mexico in that order. I need to make this list selectable using key board. ie, if i press A, it should first go to AL , then to AK etc. I have added the following code in the class which extends from Choice so that it i type A , it will go to AL. But subsequent key types for the same letter are not recognised. If anybody can provide code for this functionality, it will be great.
protected void processEvent(AWTEvent evt)
{
super.processEvent(evt);
if( evt instanceof KeyEvent)
{
char ch = ((KeyEvent)evt).getKeyChar();
Character c = new Character(ch);
if(!Character.isLetterOrDigit(ch))
{
return;
}
for(int i =0; i < getItemCount(); i++)
{
if( getItem(i).substring(0,1).equalsIgnoreCase(c.toString()))
{
select(i);
break;
}
}
}
}

Thanks in advance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!