大家好,在我的程序中有1个formatted文本字段(掩码格式)和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(" / / : ");
} 发布于 2018-12-12 21:49:14
使用setText方法:
f1_1.setText("");
f1_1.setText(null);发布于 2018-12-13 07:31:21
如果测试两个字符串是否具有相同的字符序列,则应该使用String类的equals()函数,而不是==。
我会写道:
if (c1.getSelectedItem().toString().equals(""))
而不是
if (c1.getSelectedItem().toString() == "")。
https://stackoverflow.com/questions/53744377
复制相似问题