急,急....怎样设定TextField的掩码形式? TextField passwordField = new TextField();passwordField.setEchoChar('*'); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好意思,是我没表达明白,不是做成PASSWORD,而是以定义的格式显示:比如说:2001-07-02....$300.45....或者规定其添入的数据类型...谁能解答,先谢喽,给分的! 给一个Date public class PaneJTextDate extends PlainDocument { public static String initString="####-##-##"; private static int sep1=4, sep2=7; private static int month1=5,month2=6; private static int day1=8,day2=9; private JTextComponent textComponent; private int newOffset; public PaneJTextDate(JTextComponent tc) { textComponent=tc; try { insertString(0,initString,null); } catch (Exception ex) {} } public void insertString(int offset,String s, AttributeSet attributeSet ) throws BadLocationException { int iTemp; if(s.equals(initString) ) { super.insertString(offset,s , attributeSet); } else { if(s.length()>1) { if(s.length()!=10) return; } else { try { iTemp=Integer.parseInt(s); if(offset==month1 || offset==month1-1) if(iTemp>1) return; if(offset==day1 || offset==day1-1) if(iTemp>3) return; } catch (Exception ex) { return; } } newOffset=offset; if(atSeparator(offset)) { newOffset++; textComponent.setCaretPosition(newOffset); } super.remove(newOffset,s.length()); super.insertString(newOffset,s,attributeSet); } // end if ( !=initString) } // end method insertString() public void remove(int offset,int length) throws BadLocationException { if(atSeparator(offset)) { super.remove(offset-1,1); super.insertString(offset-1,"0",null); textComponent.setCaretPosition(offset-1); } else { super.remove(offset,1); super.insertString(offset,"0",null); textComponent.setCaretPosition(offset); } }//end method remove() private boolean atSeparator(int offset) { return offset==sep1 || offset==sep2; }} // end class PaneJTextDate() JTextField不能设定掩码,请使用JClass组件,可以轻松完成掩码的设置 to NoWant:非常感谢,激动,激动(不过还没试呢) to 黑查理:JClass?能详细讲讲么? 呵,到这里下载一个看看demo可以了www.inprises.com,要我讲,给分先 数字 转换为字符串问题 validate()与组件显示的问题 怎么没有办法改变list的大小? JAVA类 高分相赠:请高手查看一下这个程序 如何调试可视化JAVABEAN? double数据类型精度问题求教 swing.JTable 修改单元值怎么不更新? 谁能告诉我这些都是什么? java初学者,求教! 又一个关于session的问题? 如何确定点击的是BACKSPACE键
比如说:2001-07-02....$300.45....
或者规定其添入的数据类型...
谁能解答,先谢喽,给分的!
public static String initString="####-##-##";
private static int sep1=4, sep2=7;
private static int month1=5,month2=6;
private static int day1=8,day2=9; private JTextComponent textComponent;
private int newOffset; public PaneJTextDate(JTextComponent tc) {
textComponent=tc;
try {
insertString(0,initString,null);
} catch (Exception ex) {}
} public void insertString(int offset,String s, AttributeSet attributeSet ) throws BadLocationException {
int iTemp;
if(s.equals(initString) ) {
super.insertString(offset,s , attributeSet);
} else {
if(s.length()>1) {
if(s.length()!=10) return;
} else {
try {
iTemp=Integer.parseInt(s);
if(offset==month1 || offset==month1-1)
if(iTemp>1) return;
if(offset==day1 || offset==day1-1)
if(iTemp>3) return; } catch (Exception ex) {
return;
}
} newOffset=offset;
if(atSeparator(offset)) {
newOffset++;
textComponent.setCaretPosition(newOffset);
}
super.remove(newOffset,s.length());
super.insertString(newOffset,s,attributeSet);
} // end if ( !=initString)
} // end method insertString() public void remove(int offset,int length) throws BadLocationException {
if(atSeparator(offset)) {
super.remove(offset-1,1);
super.insertString(offset-1,"0",null);
textComponent.setCaretPosition(offset-1);
} else {
super.remove(offset,1);
super.insertString(offset,"0",null);
textComponent.setCaretPosition(offset);
}
}//end method remove() private boolean atSeparator(int offset) {
return offset==sep1 || offset==sep2;
}} // end class PaneJTextDate()
请使用JClass组件,可以轻松完成掩码的设置
非常感谢,激动,激动(不过还没试呢)
JClass?能详细讲讲么?
www.inprises.com,
要我讲,给分先