Example usage for javax.swing JComboBox setKeySelectionManager

List of usage examples for javax.swing JComboBox setKeySelectionManager

Introduction

In this page you can find the example usage for javax.swing JComboBox setKeySelectionManager.

Prototype

@BeanProperty(bound = false, expert = true, description = "The objects that changes the selection when a key is pressed.")
public void setKeySelectionManager(KeySelectionManager aManager) 

Source Link

Document

Sets the object that translates a keyboard character into a list selection.

Usage

From source file:Main.java

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());
}

From source file:MultiKeyCombo.java

public static void main(String args[]) {
    String labels[] = { "One", "Only", "Once", "Okay", "oneself", "onlooker", "Onslaught", "Onyx", "onus",
            "onward" };
    JFrame f = new JFrame("Example JList");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JComboBox jc = new JComboBox(labels);
    MultiKeySelectionManager mk = new MultiKeySelectionManager();
    jc.setKeySelectionManager(mk);
    //    jc.setKeySelectionManager (new JComboBox.KeySelectionManager() {
    //      public int selectionForKey (char aKey, ComboBoxModel aModel) {
    //        return -1;
    //      }//from  ww  w.j  a va 2  s .  c  om
    //    });
    Container c = f.getContentPane();
    c.add(jc, BorderLayout.NORTH);
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:SelectingComboSample.java

public static void main(String args[]) {
    String labels[] = { "A", "B", "C", "D", "E", "F" };
    JFrame frame = new JFrame("Selecting JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox comboBox = new JComboBox(labels);
    frame.add(comboBox, BorderLayout.SOUTH);

    JComboBox.KeySelectionManager manager = new JComboBox.KeySelectionManager() {
        public int selectionForKey(char aKey, ComboBoxModel aModel) {
            System.out.println(aKey);
            return -1;
        }//from  w w  w. j  a  va2  s  .  c  om
    };
    comboBox.setKeySelectionManager(manager);

    frame.setSize(400, 200);
    frame.setVisible(true);
}