![](/img/trans.png)
[英]How to define a formatted text field in Swing so that the format restrictions are applied as you type?
[英]how to define an eclipse mask formatted text field?
我需要在我的jframe中放置一個帶掩碼的格式化文本字段,我這樣輸入
MaskFormatter mask = new MaskFormatter("########/##");
JFormattedTextField txtName = new JFormattedTextField(mask);
但是當我運行程序時,textField為空,並且不會將其保存在數據庫中
從MaskFormatter文檔中,我們可以看到
#
任何有效數字,使用Character.isDigit
。
如果要接受文本(字母和數字),請使用
A
任何字符或數字(Character.isLetter
或Character.isDigit
)
*
任何東西
您可能還想使用此表格
JFormattedTextField txtName = new JFormattedTextField();
MaskFormatter mask = new MaskFormatter("########/##");
mask.install(txtName);
您說它不接受文本。
但是#只表示數字
這是摘自以下表格的表格: http : //www.javalobby.org/java/forums/t48584.html
角色描述
#任何有效數字,使用Character.isDigit。
'轉義字符,用於轉義任何特殊格式的字符。
U任何字符(Character.isLetter)。 所有小寫字母都映射為大寫。
L任何字符(Character.isLetter)。 所有大寫字母都映射為小寫字母。
任何字符或數字(Character.isLetter或Character.isDigit)
? 任何字符(Character.isLetter)。
*任何東西。
H任何十六進制字符(0-9,af或AF)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.