簡體   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