简体   繁体   English

如何自定义格式化JFormattedTextField以显示IP地址?

[英]How to custom formatter JFormattedTextField to display an IP address?

I have been trying to custom JFormattedTextField to display a mask for entering an IP address. 我一直在尝试自定义JFormattedTextField以显示用于输入IP地址的掩码。

I read javadoc, and I tried with ###.###.###.### , but it's not valid in many cases. 我读了javadoc,并尝试了###.###.###.### ,但在许多情况下它无效。

I found some article for this, they use Regex to format value but they don't display a mask for entering an IP. 我找到了一些文章,他们使用正则表达式格式化值,但他们没有显示输入IP的掩码。

I want to display 3 dots in text field to display IP address. 我想在文本字段中显示3个点来显示IP地址。 Like this: 像这样:

 .   .   .

I can input a IP Address in many cases. 在很多情况下我可以输入IP地址。 You can see in IPv4 configuration in Windows. 您可以在Windows中看到IPv4配置。

 .   .   .

Can you help me? 你能帮助我吗? Thanks for reading 谢谢阅读

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 . 我知道这对你的作业没有帮助,但是对于寻找解决方案的其他人:Jidesoft Grids(我不隶属于)有一个类: com.jidesoft.field.IPTextField

Generally, I think it will be difficult to achieve a satisfactory solution with JFormattedTextField. 一般来说,我认为使用JFormattedTextField很难获得满意的解决方案。

You could try four JFormattedTextField in a row, each separated by a JLabel(".") . 您可以连续尝试四个JFormattedTextField ,每个都由JLabel(".")分隔。 With the dot out of the way, that might make the number format easier to get right. 随着点的移动,这可能使数字格式更容易正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM