Solved

Creating a Java Masked Edit Textfield

Posted on 2003-10-31
5
316 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 200 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 300 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 79
java set up 1 48
Systems talking to each other 5 110
Starting to learn JAVA, 7 48
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

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

19 Experts available now in Live!

Get 1:1 Help Now