How to custom formatter JFormattedTextField to display an IP address?

匆匆过客 提交于 2019-12-10 13:58:01

问题


I have been trying to custom JFormattedTextField to display a mask for entering an IP address.

I read javadoc, and I tried with ###.###.###.###, but it's not valid in many cases.

I found some article for this, they use Regex to format value but they don't display a mask for entering an IP.

I want to display 3 dots in text field to display IP address. Like this:

 .   .   .

I can input a IP Address in many cases. You can see in IPv4 configuration in Windows.

 .   .   .

Can you help me? Thanks for reading


回答1:


You could try four JFormattedTextField in a row, each separated by a JLabel("."). With the dot out of the way, that might make the number format easier to get right.




回答2:


I know this won't help you with your homework, but for other people looking for a solution: Jidesoft Grids (I am not affiliated) has a class for this: com.jidesoft.field.IPTextField.

Generally, I think it will be difficult to achieve a satisfactory solution with JFormattedTextField.



来源:https://stackoverflow.com/questions/12105639/how-to-custom-formatter-jformattedtextfield-to-display-an-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!