1
I am making a program and it uses some formatted Jtextfields, that is, Jformatedtextfield that calls a Maskformatter. The problem is that by writing a message and trying to erase it, the message returns, making it impossible to leave the field empty again. Does anyone have a solution for this? Here’s the code I’m using:
package main;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;
public class NewScheduleWindow extends JFrame{
JTextField hourField = new JTextField();
public NewScheduleWindow(){
try {
hourField = new JFormattedTextField(new MaskFormatter("##:##"));
} catch (ParseException e) {
e.printStackTrace();
}
add(hourField);
hourField.setBounds(160, 65, 42, 25);
hourField.setFont(Reference.setDefaultFont(15));
hourField.requestFocus();
//Etc...