Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior in Nebula CDateTime

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:

Regular CDT behavior

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:

CDateTime as a cell editor

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?

like image 366
chama Avatar asked Apr 29 '15 13:04

chama


1 Answers

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");
like image 105
CrocoB Avatar answered Nov 07 '22 16:11

CrocoB