File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 1125

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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Presenting: Auto Adjust Combo Box