简体   繁体   English

关于样式为SWT.CALENDAR的DateTime小部件

[英]About DateTime widget with style SWT.CALENDAR

我们如何检测用户是否在DateTime时间上以SWT.CALENDAR样式单击(使用鼠标)在DateTime月份,日期或年份。

Actual purpose was to get the selected date and dispose the calendar popup for single click on date, but on implementing this the problem was the calendar gets disposed even when we click on the year or month, however i have implemented it myself thanks all for your respose 实际目的是获取选定的日期并为单击的日期配置日历弹出窗口,但是在实施此方法时,问题是即使在单击年份或月份时也要处理日历,但是我自己实现了日历,谢谢大家的支持respose

if(calendarWidget.getYear() == defaultYear && calendarWidget.getMonth() == defaultMonth)
{
    //here i am getting the selected date and saving it
    defaultYear = calendarWidget.getYear();
    defaultMonth = calendarWidget.getMonth();
    shell.dispose();
}
else
{
    defaultYear = calendarWidget.getYear();
    defaultMonth = calendarWidget.getMonth();
}

here default month and year are the default selected date in calendar widget. 这里的默认月份和年份是日历小部件中默认的选定日期。

Based on Shiva answer I've added one more condition. 根据湿婆神的回答,我又添加了一个条件。 If you choose a day from another month than current, it will hide popup. 如果您从当前月份的另一个月中选择一天,它将隐藏弹出窗口。 Example: You see popup with March and you select one of the first days of April. 示例:您看到带有三月的弹出窗口,然后选择四月的第一天之一。

if((calendar.getYear() == defaultYear && calendar.getMonth() == defaultMonth) ||
                    (calendar.getYear() == defaultYear && calendar.getMonth() != defaultMonth && calendar.getDay() != defaultDay))
            {
                //here i am getting the selected date and saving it
                defaultYear = calendar.getYear();
                defaultMonth = calendar.getMonth();
                defaultDay = calendar.getDay();
                popup.dispose();
            }
            else
            {
                defaultYear = calendar.getYear();
                defaultMonth = calendar.getMonth();
                defaultDay = calendar.getDay();
            }

If you mean org.eclipse.swt.widgets.DateTime it inherit addMouseListener . 如果您的意思是org.eclipse.swt.widgets.DateTime它将继承addMouseListener

MouseListener interface has method: MouseListener接口具有以下方法:

public void mouseClicked(MouseEvent evt)

and MouseEvent has methods: MouseEvent具有以下方法:

getX()
getY()

So you can get relative position of mouse, when it is clicked and calculate on which element it is, depending on component properties. 因此,您可以在单击鼠标时获得鼠标的相对位置,并根据组件属性计算鼠标在哪个元素上。

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

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