DateTime Tutorial - ecsoya/eclipse.tutorial GitHub Wiki
DateTime是用来显示与时间相关的如年月日,时分秒的组件。它相对比较简单,我们通过一个示例来完整的学习它:
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("DateTime Tutorial");
shell.setLayout(new GridLayout(2, false));
new Label(shell, SWT.NONE).setText("Date: ");
new DateTime(shell, SWT.DATE);
new Label(shell, SWT.NONE).setText("Date(Long): ");
new DateTime(shell, SWT.DATE | SWT.LONG);
new Label(shell, SWT.NONE).setText("Date(Medium): ");
new DateTime(shell, SWT.DATE | SWT.MEDIUM);
new Label(shell, SWT.NONE).setText("Date(Short): ");
new DateTime(shell, SWT.DATE | SWT.SHORT);
new Label(shell, SWT.NONE).setText("Date(Drop Down): ");
new DateTime(shell, SWT.DATE | SWT.DROP_DOWN);
new Label(shell, SWT.NONE).setText("Time: ");
new DateTime(shell, SWT.TIME);
new Label(shell, SWT.NONE).setText("Time(Short): ");
new DateTime(shell, SWT.TIME | SWT.SHORT);
new Label(shell, SWT.NONE).setText("Calendar: ");
new DateTime(shell, SWT.CALENDAR);
shell.open();
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
效果如图:
事件监听
1. DefaultSelection:按下回车键(Enter)时触发。
2. Selection:Date或Time发生改变时触发。
参考资料:
- DateTime snippets
- 如果想了解更多的关于设置颜色,字体等其它属性的相关内容,请移步至控件的通用设置。
- 如果想了解更多的关于
Layout和LayoutData的相关内容,请移步至布局管理器。 - SWT Example: ControlExample
- Sample code and further information
上一篇:Spinner Tutorial 下一篇:Table Tutorial