3
A
回答
4
沒有內置的方式做到這一點,但你可以自己解決問題:
private static Date maxDate;
private static SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, true));
/* Set the maximum */
Calendar cal = Calendar.getInstance();
cal.set(2014, 0, 0);
maxDate = cal.getTime();
final DateTime date = new DateTime(shell, SWT.DATE | SWT.DROP_DOWN);
/* Listen for selection events */
date.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
/* Get the selection */
int day = date.getDay();
int month = date.getMonth() + 1;
int year = date.getYear();
System.out.println(day + "/" + month + "/" + year);
/* Parse the selection */
Date newDate = null;
try
{
newDate = format.parse(day + "/" + month + "/" + year);
}
catch (ParseException e)
{
return;
}
System.out.println(newDate);
/* Compare it to the maximum */
if(newDate.after(maxDate))
{
/* Set to the maximum */
Calendar cal = Calendar.getInstance();
cal.setTime(maxDate);
date.setMonth(cal.get(Calendar.MONTH));
date.setDay(cal.get(Calendar.DAY_OF_MONTH));
date.setYear(cal.get(Calendar.YEAR));
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
2
事實上,我沒有找到解決SWT日期時間限制的意思。
我認爲你必須將當前日期保存在一個變量中。之後,您可以使用偵聽器和getter方法來了解用戶選擇的日期。完成後,您可以執行自己的控制方法,並在出現問題時顯示彈出窗口。 (這是我的觀點 - >我沒有在我的舊的應用程序)
+0
葉氏!這是唯一可能的解決方案 –
相關問題
- 1. MSAccess的最大值日期/時間
- 2. 選擇時間間隔日期最大日期和最短日期
- 3. java中的最大堆空間限制
- 4. 限制最大值
- 5. 獲取兩個日期之間的最大日期/時間
- 6. SWT日期時間格式更改
- 7. 限制日期/時間選擇器
- 8. Sharepoint日期和時間字段限制
- 9. 查找最大和日期時間
- 10. 敏時間和最大日期
- 11. SQL在創建表格時檢查日期時間值限制
- 12. Android/java Sqlite:如何檢索最大日期時間?
- 13. 總結日期,數到最小和最大日期按時間間隔 - SQL
- 14. Joda日期和SWT日期時間衝突
- 15. SWT應用程序的本地化日期時間控制
- 16. 的PostgreSQL,最小值和最大值之間的行數日期
- 17. 選擇最小值和最大值日期時間只提供部分日期(年/月/日)
- 18. 限制到最大值
- 19. 設置日期時間軸限制偏移值
- 20. 獲取最大日期和最大時間
- 21. 從查詢中選擇最大日期和最大時間
- 22. 從DataRow獲取DataRow的最大日期時間值[]
- 23. MySQL月日期時間最大值計數
- 24. 錯誤在得到相應的最大值的日期時間
- 25. SQL - 選擇日期時間的最大值,按天
- 26. 從c#中的給定日期時間查找最大日期時間#
- 27. java中特定時間的日期值
- 28. SQL:另一日期/時間的24小時內的最小日期/時間值
- 29. 通過日期/時間限制刪除舊的緩存和tableview的數據通過日期/時間限制
- 30. Ionic2日期時間從最小日期
謝謝,我也在想這是解決方案! –