I've created a JDateChooser
propio, so I can make more custom changes to it later.
The problem, is that I realized, that if I choose a date on it, it just moves me to the current date. For example, if I choose 1990 or 2020, it will return me the current date, and in a format other than the "dd/MM/yyyy"
that I set. Is there any way, to make it just get and set in "dd/MM/yyyy"
format?
My attempt:
import com.toedter.calendar.JDateChooser;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class BackGr extends JFrame {
JDC data = new JDC();
JPanel painel = new JPanel();
public BackGr() {
setSize(450, 100);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
painel.add(data);
data.setPreferredSize(new Dimension(120, 20));
JTextField f = new JTextField();
painel.add(f);
f.setEditable(false);
f.setPreferredSize(new Dimension(200, 20));
JButton btSetar = new JButton("Clique");
painel.add(btSetar);
btSetar.setPreferredSize(new Dimension(70, 20));
btSetar.addActionListener((ActionEvent e) -> {
Date valor = data.getData();
f.setText("" + valor);
});
add(painel);
}
public static void main(String[] args) {
BackGr bg = new BackGr();
bg.setVisible(true);
}
}
class JDC extends JDateChooser {
public JDC() {
}
public void setData(Object valor) {
setDate(((Date) valor));
}
public Date getData() {
JDateChooser calendario = new JDateChooser(new Date(), "dd/MM/yyyy");
return (calendario.getDate());
}
}