I want to set the todays/actual date in datechooser field automatically. I've looked a couple of Stackoverflow topics about this and couldnt find a way to complete this. I dont want to output the date with system.out.println(); but I just want to save it to database (MSSQL). So for example let me show you a photo of what I mean and if you have any questions about code I can send it here, but since I dont know what code to put here that will help you I will leave it blank.
THANK YOU IN ADVANCE!
public String getDateToString(Date d) {
DateFormat da = new SimpleDateFormat("dd-MM-yyyy");
return da.format(d);
}
private void tabelaSelectedIndexChange() {
final ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel rowSM = (ListSelectionModel) e.getSource();
int selectedIndex = rowSM.getAnchorSelectionIndex();
if (selectedIndex > -1) {
Feedback f = ftm.getFeedback(selectedIndex);
//idField.setText(p.getId().toString());
arsyejaArea.setText(f.getArsyeja());
dateChooser.setDate(f.getData());
rcmb.setSelectedItem(f.getRecetaID());
recetaCMB.repaint();
}
}
});
}
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
int row = table.getSelectedRow();
if (arsyejaArea.getText().trim().isEmpty() || recetaCMB.getSelectedItem() == null || dateChooser.getDate() == null) {
JOptionPane.showMessageDialog(this, "Nuk i keni mbushur te gjitha hapesirat!");
} else if (row == -1) {
Feedback f = new Feedback();
//p.setId(Integer.parseInt(idField.getText()));
f.setArsyeja(arsyejaArea.getText());
f.setData(dateChooser.getDate());
f.setRecetaID((Receta) rcmb.getSelectedItem());
fr.create(f);
} else {
Feedback f = ftm.getFeedback(row);
//Id nuk e lejojm me ndryshu vetem emertimin ose fielda tjere qe mundeni me pas
f.setArsyeja(arsyejaArea.getText());
f.setData(dateChooser.getDate());
f.setRecetaID((Receta) rcmb.getSelectedItem());
fr.edit(f);
}
//E krijojm ni metode per me i clear fieldat mbasi ti shtojme
clear();
loadTable();
} catch (CrudFormException ex) {
JOptionPane.showMessageDialog(this, "E dhena ekziston!");
}
}

The
JCalendarconstructors include at least 3 variants which seem to allow setting the initial or 'default' date. The Java Docs of an API should be the first thing checked when there are questions in regard to achieving a goal.Given I wrote this minimal reproducible example to make the image seen in a comment above, I'll also share how to do it with a
JSpinner. If nothing else of use, it demonstrates how to get theDateof .. right now as mentioned in all 3 of the relevantJCalendarconstructors.If unable to make it work in the original code, edit to add an MRE. Note also that this example which can be copy/pasted and run, is shorter than the uncompilable code snippets included in the question.