简体   繁体   English

用户在文本字段Java Swing中输入时,屏蔽IP地址

[英]Mask the IP Address when the user enters in text field Java Swing

I have a JTextField to accommodate an ip address with 3 dots. 我有一个JTextField可以容纳3个点的IP地址。 255.120.320.123. 255.120.320.123。 When the user enters this IP address, I want to mask it like . 当用户输入此IP地址时,我想将其屏蔽为 . . I was referring this thread, How to custom formatter JFormattedTextField to display an IP address? 我指的是这个线程, 如何自定义格式化程序JFormattedTextField以显示IP地址?

jFormattedTextField did not work for me. jFormattedTextField对我不起作用。 Can anyone give me an example with jFormattedTextField with 3 dots visible? 谁能给我一个带有3个可见点的jFormattedTextField示例?

Or do I need to use 4 jFomattedTextField / JPasswordField as mentioned in this thread? 还是我需要使用此线程中提到的4个jFomattedTextField / JPasswordField

Thanks in advance. 提前致谢。

Seems you need to use MaskFormatter ,for example: 似乎您需要使用MaskFormatter ,例如:

try {
    MaskFormatter mf = new MaskFormatter("###.###.###.###");
    JFormattedTextField f = new JFormattedTextField(mf);
    add(f);
} catch (ParseException e) {
    e.printStackTrace();
}

在此处输入图片说明

I assume your trying to use JFormattedTextField? 我假设您尝试使用JFormattedTextField? Maybe you should combine it with MaskFormatter. 也许您应该将其与MaskFormatter结合使用。

Something like: // IPv4 like 192.168.1.1 像这样的东西://像192.168.1.1这样的IPv4

   MaskFormatter formatter = new MaskFormatter("###.###.###.###");
 JFormattedTextField textField = new JFormattedTextField(formatter);

Here is an Example and guide 这是一个示例和指南

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

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