I am trying to CDateTime as a cell editor for my swt table control. When I run a standalone CDateTime sample (from here), this is what it looks like:
The CDateTime is created like this:
final CDateTime cdt = new CDateTime(shell, CDT.DROP_DOWN | CDT.DATE_SHORT | CDT.COMPACT);
cdt.setSelection(new Date());
Notice the icon that is causing the drop down - it looks like a calendar. You can see the month/year, and there are 2 arrow buttons and a "today" button in the left corner of the header. The date is also written into the textbox correctly when you select a date.
However, when I try to add it as a cell editor, this is what it looks like:
Notice that the icon is different and the header parts are different. Also notice how I selected a date and get this weird number - with a month of 32! - in the text box. When the popup goes away, the date is correct, but this strange behavior looks odd and is worrying.
I created the CDateTime like this:
final int style = getStyle() | CDT.DATE_SHORT | CDT.DROP_DOWN | CDT.COMPACT ;
this.dateTime = new CDateTime(parent, style);
this.dateTime.setPattern("mm/dd/yyyy");
What am I doing wrong?
i know this is an old question, but here is the answer: the pattern you set is wrong, "mm" represents minutes. instead you can use "MM" to get the month:
dateTime.setPattern("MM/dd/yyyy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With