Strange behavior in Nebula CDateTime
Asked Answered
M

1

6

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?

Miserable answered 29/4, 2015 at 13:43 Comment(0)
A
1

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");
Apologist answered 21/8, 2015 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.