大家好, 我的程序中有 1 个 Jformattedtextfield (掩码格式)和 1 个 jcombobox;
程序首先运行良好但是;
如果我选择项目“”;即使使用 x.setvalue() 或 x.setvalue("//: "); Jformattedtextfield 也不会返回第一个格式化值并且程序卡住
我想我需要记忆一下格式,我的项目中的一些代码如下,谢谢您的提前``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);
}`
对于返回到第一个运行状态应该如何?
if (c1.getSelectedItem().toString() == "")
{
f1_1.setValue(" / / : ");
}
最佳答案
使用setText方法:
f1_1.setText("");
f1_1.setText(null);
关于java - 如何清除掩码格式的 Jformattedtextfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53744377/