[英]swt DateTime setDate() error
I have a DateTime spinner defined like this: 我有一个这样定义的DateTime微调器:
//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.
通过swt DateTime文档进行搜索,我看不到如何更新日期。
I've tried this but received an exception error: 我已经尝试过,但是收到异常错误:
//running from a method
//从方法运行
dateMin.setDate(pMinDate[0], pMinDate[1], pMinDate[2]);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! 谢谢!
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...) 它将日期时间设置为:
01/01/1999 00:00:00
(使用dd/MM/yyyy HH:mm:ss
即...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.