Good day all, there are 1 Jformattedtextfield (mask formatted) and 1 jcombobox on my program;
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(" / / : "); 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"));
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:
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 ==
.
I would write:
if (c1.getSelectedItem().toString().equals(""))
instead of
if (c1.getSelectedItem().toString() == "")
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.