Link to home
Start Free TrialLog in
Avatar of cmp2
cmp2

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of nesnemis
nesnemis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmp2
cmp2

ASKER

Thanks nesnemis,

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

Cmp2
Avatar of cmp2

ASKER

Nevermind, I figured it out.

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

Thanks for the suggestion.