0

I am making an edit page for a booking program in which one of the things the user can edit is a begin date and an end date of a certain booking. At the moment the user can select the booking and the info will be put into the JTextFields but not the JDatePickers (the ones used for the begin and end date).

Now it is:

enter image description here

But it should look something like this (I put in the dates manually): enter image description here

but I'cant find out how to programmatically set the dates in a JDatePicker. I followed this tutorial and came up with this decleration for the JDatePickers, One for the enddate One for the begindate:

    pBooking.put("text.today", "Today");
    pBooking.put("text.month", "Month");
    pBooking.put("text.year", "Year");

    beginDatePanelBooking = new JDatePanelImpl(beginModelBooking, pBooking);
    endDatePanelBooking = new JDatePanelImpl(endModelBooking, pBooking);
    beginDatePickerBooking = new JDatePickerImpl(beginDatePanelBooking, new DateLabelFormatter());
    endDatePickerBooking = new JDatePickerImpl(endDatePanelBooking, new DateLabelFormatter());

I also made a small example here which can be used to simulate the problem i'm having:

BRHSM
  • 854
  • 3
  • 13
  • 48
  • check this: http://stackoverflow.com/a/27213567/784540 –  Apr 24 '17 at 14:52
  • that's a different libary i think. I use the JDatePicker while that is the JDateChooser. check the website I linked – BRHSM Apr 24 '17 at 15:01
  • 2
    A rudimentary search of the [Java Docs for `JDatePicker`](https://jar-download.com//javaDoc/org.jdatepicker/jdatepicker/1.3.4/org/jdatepicker/JDateComponent.html) suggests it has a `getModel()` method. Inspect the Java Docs for [the object it returns](https://jar-download.com//javaDoc/org.jdatepicker/jdatepicker/1.3.4/org/jdatepicker/DateModel.html).. As a general rule, always Read The Fine Manual before using a component, and certainly before asking here. – Andrew Thompson Apr 24 '17 at 15:11
  • I'm voting to close this question as off-topic because reading the [JavaDocs for the API](https://jar-download.com//javaDoc/org.jdatepicker/jdatepicker/1.3.4/org/jdatepicker/JDateComponent.html) would provide the solution – MadProgrammer Apr 24 '17 at 21:58

1 Answers1

2

You can use JXDatePicker from SwingX. Tutorial: Introduction to the JXDatePicker.

Cem Ikta
  • 1,330
  • 12
  • 12