Formatting a JTextField to only allow ip addresses?

  • Follow


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 


0
Reply Ken 1/27/2005 7:02:24 AM

In article <4m0Kd.153964$KO5.74217@clgrps13>,
 "Ken Adams" <hockeyGuy17@hotmail.com> wrote:

>: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 

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 =
-- 
Steve W. Jackson
Montgomery, Alabama
0
Reply Steve 1/27/2005 4:37:45 PM


You can attach a specialized document to your textfield. Or use the 
JFormattedTextField with a MaskFormatter.


Steve W. Jackson wrote:
> In article <4m0Kd.153964$KO5.74217@clgrps13>,
>  "Ken Adams" <hockeyGuy17@hotmail.com> wrote:
> 
> 
>>: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 
> 
> 
> 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 =
0
Reply Symon 1/27/2005 9:47:04 PM

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.


-- 
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
0
Reply ptomblin 1/27/2005 10:35:02 PM

Ken Adams wrote:

> 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

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.

-- 
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
0
Reply Nigel 1/28/2005 9:57:08 AM

4 Replies
1352 Views

(page loaded in 0.102 seconds)

Similiar Articles:













7/22/2012 4:43:29 PM


Reply: