BRHSM
BRHSM

Reputation: 884

Is there a way to set the date value on a JDatePicker

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:

Upvotes: 0

Views: 1125

Answers (1)

Cem Ikta
Cem Ikta

Reputation: 1450

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

Upvotes: 2

Related Questions