Question ~ I have an AddButton ActionListener that I'm trying to empty a JFormattedTextField with while keeping it's Mask("##/##/####") and SimpleDateFormat. If anyone can help me with the technical part of this, that would be cool. Thanks! When button is clicked, text of the JFormattedTextField is emptied, but i get exception if I try to setValue(df) or makeMask()
private JPanel borderPanel, northPanel, westPanel;
private JTextField name, location;
private JFormattedTextField date;
private static final DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
private MaskFormatter mask = null;
private JButton add, remove;
private static final int FRAME_WIDTH = 850;
private static final int FRAME_HEIGHT = 600;
public FoodGUI() {
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setLocationRelativeTo(null);
// Creates the BorderLayout Panel which contains every item nested within each individual panel
createBorderPanel();
}
class AddButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
name.setText("");
location.setText("");
try {
date.setValue(new Date());
date.setText("");
} catch(Exception e1) {
System.out.println("Hello error");
}
// date.setValue(df);
// makeMask(date);
}
}
My makeMask method and simple date formats are orginally applied in the private JPanel that the JFormattedTextBox is created in.
public void makeMask(JFormattedTextField e) {
try {
mask = new MaskFormatter("##/##/####");
mask.setPlaceholderCharacter('-');
mask.install(e);
} catch (ParseException ex) {
Logger.getLogger(FoodGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}