[英]How to clear mask formatted Jformattedtextfield
Good day all, there are 1 Jformattedtextfield (mask formatted) and 1 jcombobox on my program; 一切顺利,我的程序中有1个Jformattedtextfield(掩码格式)和1个jcombobox。
The program running well first but ; 该程序首先运行良好,但是;
If I select item ""; 如果我选择项目“”; Jformattedtextfield doesn't return to first formatted value even used x.setvalue() or x.setvalue(" / / : ");
即使使用x.setvalue()或x.setvalue(“ / /:”),Jformattedtextfield也不返回第一个格式化值。 and program freezes
和程序冻结
i think i need to recall the format, some codes from my project as below, thank you for advance ``JFormattedTextField f1 = new JFormattedTextField(new SimpleDateFormat("dd-MM-yyyy HH:mm")); 我认为我需要回顾一下我的项目中的格式,一些代码,如下所示,感谢您的提前:``JFormattedTextField f1 = new JFormattedTextField(new SimpleDateFormat(“ dd-MM-yyyy HH:mm”));
f1_1 = new JFormattedTextField();
f1_1.setFont(new Font("Calibri", Font.PLAIN, 12));
f1_1.setBounds(88, 97, 104, 30);
panel.add(f1_1);
try {
MaskFormatter dateMask = new MaskFormatter(" ##/##/#### ##:##");
dateMask.install(f1_1);
}
catch (ParseException ex) {
Logger.getLogger(MaskFormatter.class.getName()).log(Level.SEVERE, null, ex);
}`
For the return to the first running condition how it should be ? 为了返回到第一运行状态应该如何?
if (c1.getSelectedItem().toString() == "")
{
f1_1.setValue(" / / : ");
}
use setText method: 使用setText方法:
f1_1.setText("");
f1_1.setText(null);
If you test if two strings have the same sequence of characters, you should use the equals()
function of the class String
instead of ==
. 如果测试两个字符串是否具有相同的字符序列,则应使用
String
类的equals()
函数而不是==
。
I would write: 我会写:
if (c1.getSelectedItem().toString().equals(""))
instead of 代替
if (c1.getSelectedItem().toString() == "")
. if (c1.getSelectedItem().toString() == "")
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.