Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2005

Tip: Looking for answers? Try searching our database.

JFormattedTextField

Thread view: 
rspuler@yahoo.com - 16 Sep 2005 11:27 GMT
I have a problem with the class JFormattedTextField. Maybe someone has
already solved this.

Is there any possibility to restrict the valid characters depending on
the position inside the mask (besides the available distinction
Letter/Number etc).

What I want is e.g. that first char must be [0-2] second char must be
[0-4] thrid char [0-5] etc.

I think one can not do this with the standart swing classes?

Thanks for any help
Oliver Wong - 16 Sep 2005 16:43 GMT
>I have a problem with the class JFormattedTextField. Maybe someone has
> already solved this.
[quoted text clipped - 7 lines]
>
> I think one can not do this with the standart swing classes?

   See the javadocs for the javax.swing.InputVerifier class.

   - Oliver
Roedy Green - 16 Sep 2005 20:32 GMT
>I think one can not do this with the standart swing classes?

I did it with AWT classes, so surely you can do it with Swing.  It is
just a matter of how much code you are willing to write.

see http://mindprod.com/jgloss/validation.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

bassclar - 22 Sep 2005 19:17 GMT
rspu...@yahoo.com wrote:
> I have a problem with the class JFormattedTextField. Maybe someone has
> already solved this.
[quoted text clipped - 5 lines]
> What I want is e.g. that first char must be [0-2] second char must be
> [0-4] thrid char [0-5] etc.

I'm not sure exactly what you mean by "etc." here but, depending on
how how many digits might be allowed, regular expressions might do
the trick.

My best guess is that you want to force the input string to be between
one and eight digits long. (The ninth char couldn't really be in the
[0-10] range, since 10 doesn't fit in a char.)

In this case you could do the following. It's ugly but it works.

java.util.regex.Pattern pat = java.util.regex.Pattern.compile(
 "[0-2]([0-3]([0-4]([0-5]([0-6]([0-7]([0-8]([0-9])?)?)?)?)?)?)?");
JFormattedTextField ftf =
 new JFormattedTextField(new RegexPatternFormatter(pat));

This uses RegexPatternFormatter from the 2nd edition of the O'Reilly
book "Java Swing":
<http://examples.oreilly.com/jswing2/code/ch20/RegexPatternFormatter.java>

It's not part of the JDK but it's only about 20 lines long and you are
allowed to use it. At least you are probably allowed to use it--see
<http://www.oreilly.com/pub/a/oreilly/ask_tim/2001/codepolicy.html>.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.