• Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox Key Selection  RSS feed

 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to allow elements in a JComboBox be selected by the first letter of the item. I'm assuming I should be using a key selection manager. Anyone have an example of how to do this?
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works out-of-the-box for me, both with the cross platform look&feel and the Windows system look&feel:
In Java 6, there is a slight delay though when pressing keys to allow a sort of history; when typing "Java" for instance it does not look for J first, then A, then V and then A (like Java 1.4 does), but it really searches for Java.
 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm.... That doesn't seem to work for me in an application that was recently upgraded from Java 1.3 to Java 1.5. It used to work in Java 1.3 but not in Java 1.5. This combo box is in a JTable if that matters.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It probably does
I just tried it, and it doesn't work out-of-the-box in JTables. You might want to try adding a key listener to the renderer, but I have no idea if that would work.
 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the key listener but had no luck. Any other ideas?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I am trying to allow elements in a JComboBox be selected by the first letter of the item.

works OK in sun's example (but as an editor only)

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#combobox

code is in the link TableRenderDemo.java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!