1

I am using a combo box where values are displayed and i have already checked editable true. I am using netBeans. I have values in the combo box for e.g.

  • Apple
  • Ant
  • Ape
  • Bottle
  • Bat
  • Ball

So when i will type A in the combo box it should display Apple, Ant, Ape in the list. Is there a way to do this?I have use decorate also but it not good.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
stella
  • 47
  • 7
  • Probably you could try adding a key listener to the combobox and filtering the entries accordingly. Could you add some minimal running code so it's easier for us to reproduce the problem? – tobias_k Mar 20 '14 at 09:19
  • There's no default auto-complete functionality. You can look at the links from [this answer](http://stackoverflow.com/a/13682101/2587435) to see a couple options. – Paul Samsotha Mar 20 '14 at 09:21
  • possible duplicate of [Auto complete combo box in java](http://stackoverflow.com/questions/22562131/auto-complete-combo-box-in-java) – Jeffrey Bosboom Jun 30 '14 at 18:21

1 Answers1

0

I would use a JTextField that does this:

int num = 0;
while(true){
if(comboBox.getComponentAt(num).getString().toLowerCase().toCharArray()[0] == JTextField.getText.toLowerCase().toCharArray()[0){

if(num == null){
num == 0;
}
//code to switch current item in JComboBox (sorry, don't know that code)
JTextField.setText("");
num++;

}

    }

The user starts typing, and than the program automatically scans the text, and finds if the first letter in the JTextField is the same as the label in one of the labels as one of the JComboBox items.

Hope this works!