Reputation: 1178
Im using netbeans and I would like to know, how to set the max text limit that can be displayed in swing jcombobox
I have checked the properties window for the jcombobox, but I could not find any property for setting the text limit.
Any help on this is much appreciated.
Upvotes: 2
Views: 724
Reputation: 324118
how do I limit the number of characters that the user can enter in jcombo box.
You can add a DocumentFilter
to the editor of the combo box:
ComboBoxEditor editor = comboBox.getEditor();
JTextField textField = (JTextField)editor.getEditorComponent();
AbstractDocument doc = (AbstractDocument)textField.getDocument();
doc.setDocumentFilter( ...);
Read the section from the Swing tutorial on Implementing a DocumentFilter for an example filter the limits the number of characters that can be entered.
Upvotes: 1