Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"Intillegent" JComboBox  RSS feed

 
Markus Schmider
Ranch Hand
Posts: 148
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I need to implement an editable JComboBox. It should display a list of rivers from a database. However since the number of rivers is very large, the entries must be dynamically filled after the user has typed in three or more letters.
I have tried to solve this using a KeyAdapter. Everythings works. However after the user has typed in three characters, these three characters are selected in the Combobox. Of course when the user continues to type these chars will be replaced.
I have so far not found a solution to deselect the characters and place the cursor at the end.



 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at http://www.coderanch.com/t/429206/GUI/java/dynamic-dropdown for some ideas.
Also check out the 'similar threads' section at the end of this page
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see a reason why all the text are selected after typing 3 characters.
However, if it happens type ((JTextField)fliessgewaesserComboBox.getEditor().getEditorComponent()).setCaretPosition(searchString.length()); at the end of the keyReleased() event.
But after you entered this, when you release any key, the cursor goto the end. I think you can find a way to avoid that..
 
Markus Schmider
Ranch Hand
Posts: 148
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved the problem with a document listener.
The important point is to do the updating of the model within
SwingUtilities.invokeLater(new Runnable() {
public void run() {





Thanks for your kind replies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!