How can I get an event when the user types a key in the TextField of a JComboBox?
Created May 4, 2012
Sandip Chitale This simply becomes a problem of getting at the textfield of a editable combobox.
if (combo.isEditable()) { Component c = combo.getEditor().getEditorComponent(); if (c instanceof JTextField) { JTextField tf = (JTextField) c; // now listen for key types or // add Document listener to the // backing the textfield } }How to listen on typed keys is a well understood problem. Hints are -
- textfield.addKeyListener(...)
- textfield.getDocument().addDocumentListsner(...); // better