Solved

Creating a Java Masked Edit Textfield

Posted on 2003-10-31
5
324 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
[X]
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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

623 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