File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editable JComboBox that must accept only alphabets

 
sandy
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How can a editable JComboBox made to accept only Lowercase and Uppercase Alphabets ? Any suggestions ?
Sandy
:roll:
 
Rene Liebmann
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I see two possibilities. The easier one is to check, when actionPerformed event is fired, which element of the combobox is selected. Then you have a string and you can parse every single character, if it is a right one.
The second possibility I see, you need to register a KeyListener to the editor of the ComboBox. To get this, you need to call:
JComboBox.getEditor().getEditorComponent();
Then you catch every keyTyped event and you ask for a correct input.
Hope this helps
Rene
 
sandy
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rene
Thanks a lot for the suggestion, but my query was if the user types in some string, how can the ComboBox prevent him from typing the wrong characters i.e the validation should be correct only for Alphabets, something of what a PlainDocument does for the TextField validation.Since ComboBox does'nt validate for Key events, how can this be achieved ?
Regards
Sandhya
 
Rene Liebmann
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
here is a little test:

Is this what you want?
 
sandy
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rene
Thanks a lot ! It worked and yeah, this is what I wanted. Thanks again!!
Sandhya
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sandy" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic