Adding a "formatter" to an editable JComboBox

Hi,

How do I make an editable JCombobox behave like a JFormattedTextFiled with a Formatter (i.e. not allow certain characters such a commas and periods)?

Thanks,

Cmp2
cmp2Asked:
Who is Participating?
 
nesnemisConnect With a Mentor Commented:
You can use DocumentFilter on the strings that you want to input in your comboboxes
0
 
cmp2Author Commented:
Thanks nesnemis,

I know how to add a DocumentFilter on a text field, but how do you add a FilterDocument to a JComboBox?

Cmp2
0
 
cmp2Author Commented:
Nevermind, I figured it out.

JComboBox a = new JComboBox();
JTextField c = (JTextField)a.getEditor().getEditorComponent();
c.setDocument(...);

Thanks for the suggestion.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.