The Artima Developer Community
Sponsored Link

Java Answers Forum
Customizing JFormattedTextField to create IP Address Field

1 reply on 1 page. Most recent reply: Aug 25, 2003 5:39 PM by zhangfeng

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Kate Lapan Fox

Posts: 2
Nickname: kfox
Registered: Aug, 2002

Customizing JFormattedTextField to create IP Address Field Posted: Aug 21, 2002 2:52 PM
Reply to this message Reply
Advertisement
I'm trying to create an IP Address field that will be very intuitive.

I've a JFormattedTextField that I've customized. It looks good, but I want to make it have more functionality. I can't find a way to intercept user entry after every character. I've looked on the net but I've only been able to find how to do the simplest things.

My code below:

<java>
import java.awt.Font;
import javax.swing.text.MaskFormatter;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class IPAddressTest {

public static void main(String[] args) {
JFrame frame = new JFrame("ip address test");
JPanel panel = new JPanel();

try {
MaskFormatter ipmask = new MaskFormatter("###.###.###.###");
ipmask.setPlaceholderCharacter(' ');
JFormattedTextField field = new JFormattedTextField(ipmask);
field.setFont(new Font("Courier", Font.PLAIN, 12));
field.setColumns(16);
panel.add(field);
} catch (Exception e) {
e.printStackTrace();
}

frame.getContentPane().add(panel);
frame.pack();
frame.show();
}
}
</java>


zhangfeng

Posts: 1
Nickname: zhinux
Registered: Aug, 2003

Re: Customizing JFormattedTextField to create IP Address Field Posted: Aug 25, 2003 5:39 PM
Reply to this message Reply
How to control the segment's size ?

thx!

Flat View: This topic has 1 reply on 1 page
Topic: File size Previous Topic   Next Topic Topic: Thumb rule for access specifiers in inheritance

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use