Two Laptop Bag
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes IP address in JFormattedTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "IP address in JFormattedTextField" Watch "IP address in JFormattedTextField" New topic

IP address in JFormattedTextField

Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Hi to everyone,

I'm trying to get the IP address in JTextField like (for client to connect Server). I used new MaskFormatter("###.###.###.###") but it doesn't work properly in many cases. Do i need to write some code to get proper input or you guys can tell any better solution.

I'm also considering of taking input in 4 text boxes but i'll wait for your valueable suggestions.

Thanks! in advance
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

Howdy, Tahir!

Champion, in my case, here's what I did: I simply provided a JTextField for the user to provide the server's IP address (and the user can provide really anything). Before trying to connect, I verify if the user provided a valid IP address (by using regular expression); if so, then the client tries to connect to the server, otherwise, a message box, saying that the provided IP address is invalid, is displayed.

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
K. Tsang

Joined: Sep 13, 2007
Posts: 3134

You may want to check this out

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8411

Hi Tahir,

You could also take a look at this thread.

Good luck!
Kind regards,

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
I agree. Here's the link:
subject: IP address in JFormattedTextField
It's not a secret anymore!