This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Presenting: Auto Adjust Combo Box  RSS feed

Avi Abrami
Ranch Hand
Posts: 1141
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!