繁体   English   中英

swt DateTime setDate()错误

[英]swt DateTime setDate() error

我有一个这样定义的DateTime微调器:

 //Class Global
 DateTime dateMin = null;

 //added to the UI
 DateTime dateMin = new DateTime(grpPlaybackSearchOptions, SWT.BORDER);
 dateMin.setBounds(335, 44, 123, 23);

稍后在我的代码中,我希望用户能够加载可能已经保存的日期。 通过swt DateTime文档进行搜索,我看不到如何更新日期。

我已经尝试过,但是收到异常错误:

//从方法运行
dateMin.setDate(pMinDate [0],pMinDate [1],pMinDate [2]);

可以不更新对象,还是我尝试不正确地更新对象?

谢谢!

不确定您要做什么,文档非常清楚并提供了方法:

setDate(int year, int month, int day)
setHours(int hours)
setMinutes(int minutes)
setSeconds(int seconds)

这是一个简单的示例:

public static void main(String[] args)
{
    final Display display = new Display();

    Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(1, false));

    final DateTime date = new DateTime(shell, SWT.DATE);
    final DateTime time = new DateTime(shell, SWT.TIME);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change date");
    button.addListener(SWT.Selection, new Listener()
    {
        @Override
        public void handleEvent(Event arg0)
        {
            date.setDate(1999, 0, 1);
            time.setHours(0);
            time.setMinutes(0);
            time.setSeconds(0);
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

它将日期时间设置为: 01/01/1999 00:00:00 (使用dd/MM/yyyy HH:mm:ss即...)

暂无
暂无

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

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