用户在文本字段Java Swing中输入时,屏蔽IP地址 [英] Mask the IP Address when the user enters in text field Java Swing
问题描述
我有一个JTextField可以容纳3个点的IP地址. 255.120.320.123.当用户输入此IP地址时,我想像 . . . 我指的是这个线程,如何将格式化程序JFormattedTextField定制为显示IP地址?
I have a JTextField to accommodate an ip address with 3 dots. 255.120.320.123. When the user enters this IP address, I want to mask it like ... I was referring this thread, How to custom formatter JFormattedTextField to display an IP address?
jFormattedTextField
对我不起作用.谁能给我举一个带有3个可见点的jFormattedTextField
示例?
jFormattedTextField
did not work for me. Can anyone give me an example with jFormattedTextField
with 3 dots visible?
还是我需要使用此线程中提到的4个jFomattedTextField
/JPasswordField
?
Or do I need to use 4 jFomattedTextField
/JPasswordField
as mentioned in this thread?
谢谢.
推荐答案
Seems you need to use MaskFormatter
,for example:
try {
MaskFormatter mf = new MaskFormatter("###.###.###.###");
JFormattedTextField f = new JFormattedTextField(mf);
add(f);
} catch (ParseException e) {
e.printStackTrace();
}
这篇关于用户在文本字段Java Swing中输入时,屏蔽IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!