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 / January 2005

Tip: Looking for answers? Try searching our database.

Formatting a JTextField to only allow ip addresses?

Thread view: 
Ken Adams - 27 Jan 2005 07:02 GMT
Anybody know of a free custom swing component that represents an IP address.
Or does anybody know how to format a JTextField to only allow ip addresses.
So basically I want to keep it in the form 192.168.1.101.

Any suggestions

Thanks
Steve W. Jackson - 27 Jan 2005 16:37 GMT
>:Anybody know of a free custom swing component that represents an IP address.
>:Or does anybody know how to format a JTextField to only allow ip addresses.
[quoted text clipped - 3 lines]
>:
>:Thanks

Personally, I would suggest using four fields instead of one, where each
individual field can contain values ranging from 000 to 255 and perhaps
typing the third digit could even auto-tab out to the next field.

It would be far easier to write a single JTextField subclass that
accepts only numeric input and only a max set of digits, etc.  You can
easily display these in such a way that the dots appear between them on
other components.  And with a little experimentation, you might even be
able to set up other restrictions if needed, like not allowing 000 in
certain octets.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Symon - 27 Jan 2005 21:47 GMT
You can attach a specialized document to your textfield. Or use the
JFormattedTextField with a MaskFormatter.

>>:Anybody know of a free custom swing component that represents an IP address.
>>:Or does anybody know how to format a JTextField to only allow ip addresses.
[quoted text clipped - 16 lines]
>
> = Steve =
Paul Tomblin - 27 Jan 2005 22:35 GMT
In a previous article, Symon <symon@tatouage.fr> said:
>You can attach a specialized document to your textfield. Or use the
>JFormattedTextField with a MaskFormatter.

I know of no way to make JFormattedTextField with a MaskFormatter restrict
to a maximum value.  It would be hard enough to do what I want (for
entering times, restrict the minutes and seconds parts to 00-59), but it
would be much, much harder to restrict a field to 0-255.

Signature

Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/
I haven't had any mail from my mother since her ISP ended up in the RBL.
I deny that I nominated them...
             -- Peter Corlett

Nigel Wade - 28 Jan 2005 09:57 GMT
> Anybody know of a free custom swing component that represents an IP address.
> Or does anybody know how to format a JTextField to only allow ip addresses.
[quoted text clipped - 3 lines]
>
> Thanks

I think this covers the subject pretty well:

http://java.sun.com/developer/JDCTechTips/2001/tt1120.html

The 4th way (MVC) is probably the best for this case.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555



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.