Java Swing Tutorial - Java JComboBox .setKeySelectionManager (JComboBox .KeySelectionManager aManager)








Syntax

JComboBox.setKeySelectionManager(JComboBox.KeySelectionManager aManager) has the following syntax.

public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)

Example

In the following code shows how to use JComboBox.setKeySelectionManager(JComboBox.KeySelectionManager aManager) method.

/*from www  .  j  a  v a2s  . c o m*/
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;

public class Main {
  public static void main(String[] argv) throws Exception {
    String[] items = { "A", "A", "B", "B", "C", "C" };
    JComboBox cb = new JComboBox(items);
    cb.setKeySelectionManager(new MyKeySelectionManager());
  }
}

class MyKeySelectionManager implements JComboBox.KeySelectionManager {
  long lastKeyTime = 0;
  String pattern = "";

  public int selectionForKey(char aKey, ComboBoxModel model) {
    return 1;
  }
}