This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Presenting: Auto Adjust Combo Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Presenting: Auto Adjust Combo Box" Watch "Presenting: Auto Adjust Combo Box" New topic
Author

Presenting: Auto Adjust Combo Box

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Dear Reader,
Below is code for a class that implements javax.swing.event.DocumentListener that is intended to be used in conjunction with an editable javax.swing.JComboBox
As you type into the text field, i.e. the editor component, the list of values in the popup automatically changes so as to display only those values that contain the text currently appearing in the text field.
For example if you type A, the popup displays all values that contain A.
If you type AB, the popup displays all values that contain AB.
Note that the listener is case sensitive. In other words, typing AB will not display values containing Ab or aB or ab.
Note that this is a first draft.
Also note that navigating the popup list via the keyboard may not be as you would expect.
Lastly, I make no promises or guarantees that I will respond to requests for modifying the below code.
In order to use the below class, add it as a DocumentListener to the javax.swing.text.Document associated with the JComboBox's editor component, e.g.

And here is the code for class DocLstnr

 
 
subject: Presenting: Auto Adjust Combo Box
 
Similar Threads
MultipleSelect JComboBox
Generate random strings
JPopupMenu issue with windows
Print out values of xml tags
dynamic dropdown