简体   繁体   English

星云CDateTime中的奇怪行为

[英]Strange behavior in Nebula CDateTime

I am trying to CDateTime as a cell editor for my swt table control. 我正在尝试将CDateTime作为我的swt表控件的单元格编辑器。 When I run a standalone CDateTime sample (from here ), this is what it looks like: 当我运行一个独立的CDateTime示例(从这里 ),它是这样的:

定期CDT行为

The CDateTime is created like this: CDateTime的创建方式如下:

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. 您可以看到月/年,标题的左下角有2个箭头按钮和“今天”按钮。 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作为单元格编辑器

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! 还要注意我是如何选择一个日期并得到这个奇怪的数字 - 一个月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: 我像这样创建了CDateTime:

    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. 我知道这是一个老问题,但答案是:你设置的模式是错误的,“mm”表示分钟。 instead you can use "MM" to get the month: 相反,你可以使用“MM”来获得月份:

    dateTime.setPattern("MM/dd/yyyy");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM