Solved

Adding a "formatter" to an editable JComboBox

Posted on 2004-09-26
3
421 Views
Last Modified: 2008-01-16
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
Comment
Question by:cmp2
  • 2
3 Comments
 
LVL 3

Accepted Solution

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

Author Comment

by:cmp2
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?

Cmp2
0
 

Author Comment

by:cmp2
ID: 12162381
Nevermind, I figured it out.

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

Thanks for the suggestion.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now