Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating a Java Masked Edit Textfield

Posted on 2003-10-31
5
Medium Priority
?
329 Views
Last Modified: 2006-11-17
I'm trying to create a class that extends jTextField that closely mimicks the VB 6 MaskedEditControl.  The way I'm planning to implement it is: when the user types in the textbox, I want to check the new text against the mask before showing it.  It will filter out any text that does not match the mask.

The problem is, I don't know what event to use.  If I use the KeyPressed or KeyTyped events, everything works fine, and I can check the text against the mask, but whatever the user had typed in shows up at the end of the textbox.

If I use the jTextField's Document's textInserted event, I can check the new text against the mask, but, when I go to put the checked text back into the textbox, it of course fires the textInserted event, and I end up in an infinate loop.

So, my question is:  If I use the KeyPressed/KeyTyped event, can I somehow make it so that the Key that was Pressed/Typed is NOT inserted into the textbox?  -OR- If I use the Document's textInserted event, is there a way where I can stop listening for a textInserted event while I'm changing the text, then, start listening for the textInserted event again once I'm finished?
0
Comment
Question by:snapdrag0n420
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9659741
There is this:

It's a bit old, but should work...

http://www.sys-con.com/java/source.cfm?id=416
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 800 total points
ID: 9659764
This is the article that goes along with the code

http://www.sys-con.com/java/article.cfm?id=416
0
 
LVL 92

Accepted Solution

by:
objects earned 1200 total points
ID: 9661421
Try using a JFormattedTextField.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9662405
Ooooooh!  Good old Java 1.4!

See?  Told you that article was old :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 10115118
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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 This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

926 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