Question

I have a DateTime spinner defined like this:

 //Class Global
 DateTime dateMin = null;

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

later on in my code I'd like the user to be able to load a date that may have been saved off. Digging through the swt DateTime docs I'm not seeing how I can update the date.

I've tried this but received an exception error:

//running from a method
dateMin.setDate(pMinDate[0], pMinDate[1], pMinDate[2]);

Can the object be not be updated or am I trying to update the object incorrectly?

Thanks!

Was it helpful?

Solution

Not sure what you are struggling with, the documentation is very clear and provides the methods:

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

Here is a simple example:

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();
    }
}

It will set the datetime to: 01/01/1999 00:00:00 (using dd/MM/yyyy HH:mm:ss that is...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top