所以我有这个FormatedTextField
JFormattedTextField myFtf = new JFormattedTextField();
具有以下掩码,放在我的应用程序构造函数
中try {
myFtf.setFormatterFactory(
new DefaultFormatterFactory(
new MaskFormatter("###.###.###-##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
然后,我有两个单选按钮,应该在myFtf
中更改掩码格式化程序。
我尝试了以下内容:
private radioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
myFtf.setFormatterFactory(
new DefaultFormatterFactory(
new MaskFormatter("###.###.###-##")));
} catch (Exception e) {
e.printStackTrace();
}
}
private void radioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
myFtf.setFormatterFactory(
new DefaultFormatterFactory(
new MaskFormatter("##.###.###/####-##")));
} catch (Exception e) {
e.printStackTrace();
}
}
哪个工作正常,直到我在文本字段中有输入时尝试更改其掩码。如果有,它不再改变面具。这是一些印刷品:
确定方案:
img a:
切换单选按钮给了我这个:
img b:
越野车场景:
img c:
切换单选按钮给了我这个:
img d:
我希望 img d 与 img a
完全相同如何正确动态更改其遮罩?
答案 0 :(得分:0)
将您的动作侦听器更改为:
private radioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
myFtf.setFormatterFactory(
new DefaultFormatterFactory(
new MaskFormatter("###.###.###-##")));
myFtf.setText("");
} catch (Exception e) {
e.printStackTrace();
}
}
private void radioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
myFtf.setFormatterFactory(
new DefaultFormatterFactory(
new MaskFormatter("##.###.###/####-##")));
myFtf.setText("");
} catch (Exception e) {
e.printStackTrace();
}
}
那应该清除文本字段。 祝你好运!
答案 1 :(得分:0)
我让它正常工作!我需要做的就是添加一个
myFtf.setText("")
设置新格式化工厂后。 ; first of all, set the video mode
mov ah, 0x00 ; function: set video mode
mov al, 0x03 ; video mode: 0x03
int 0x10
; set the cursor position to 0:0 (DH:DL)
mov ah, 0x02 ; function: set cursor position
xor bh, bh ; page: 0x00
xor dh, dh ; row: 0x00
xor dl, dl ; column: 0x00
int 0x10
; read row into DH
call read_num
mov dh, dl
; if you want to, you can read a separator character between them
; call read_num
; read column into DL
call read_num
; set the cursor position again to DH:DL
mov ah, 0x02 ; function: set cursor position
xor bh, bh ; bh: just to make sure BH remains 0x00
int 0x10
...
read_num: ; will read two decimal characters from input to DL
; DOS interrupt for reading a single characted
mov ah, 0x01 ; function: read a character from STDIN
int 0x21
and al, 0x0F ; get the number from the ASCII code
mov bl, 0x0A
mul bl ; move it to the place of tens
mov dl, al ; dl = al*10
; DOS interrupt for reading another char
mov ah, 0x01 ; function: read a character from STDIN
int 0x21
and al, 0x0F
add dl, al ; dl = dl + al
ret
没有按预期工作,但这是一个近景! :-)