• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

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
0
cmp2
Asked:
cmp2
  • 2
1 Solution
 
nesnemisCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now