Adding a "formatter" to an editable JComboBox

Posted on 2004-09-26
Last Modified: 2008-01-16

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)?


Question by:cmp2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

nesnemis earned 125 total points
ID: 12157725
You can use DocumentFilter on the strings that you want to input in your comboboxes

Author Comment

ID: 12162182
Thanks nesnemis,

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


Author Comment

ID: 12162381
Nevermind, I figured it out.

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

Thanks for the suggestion.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
null output 3 58
jmss example java 2 48
ejb message driven bean mdb creation steps 2 54
spring maven example issues 3 99
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question