Ho il seguente codice:
Il problema è il seguente,codice:package it.example; import java.awt.Container; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.BoxLayout; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.text.DateFormatter; public class JFormattedTextExample { public static void main(String args[]) throws ParseException { JFrame f = new JFrame("Dati"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); DateFormatter df = new DateFormatter(format); //Once you've specified the input format, you would then pass the formatter into the JFormattedTextField constructor, as shown below: JFormattedTextField dataJFTF = new JFormattedTextField(df); dataJFTF.setValue(new Date()); content.add(dataJFTF); JTextField nomeJTF = new JTextField(); content.add(nomeJTF); f.setSize(300, 100); f.setVisible(true); } }
Step A: immetta una data nel primo campo
Step B: passo il focus sul secondo campo
Step C: cancello la data immessa al punto A
Step D: passo il focus sul secondo campo
Al passo D mi si verifica il mio problema, appena passo il focus sul secondo campo, nel primo campo viene visualizzata la data immessa al passo A
Come faccio a dirgli che se cancello la data, non mi deve visualizzare nulla?

Rispondi quotando