|
|
@ -10,7 +10,6 @@ import javax.swing.text.JTextComponent; |
|
|
|
import javax.swing.text.PlainDocument; |
|
|
|
import javax.swing.text.PlainDocument; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JDateDocument extends PlainDocument{ |
|
|
|
public class JDateDocument extends PlainDocument{ |
|
|
|
private JTextComponent textComponent; //日期输入文本框
|
|
|
|
private JTextComponent textComponent; //日期输入文本框
|
|
|
@ -36,39 +35,19 @@ public class JDateDocument extends PlainDocument { |
|
|
|
SimpleDateFormat dateFormat, |
|
|
|
SimpleDateFormat dateFormat, |
|
|
|
String initDateTime) throws |
|
|
|
String initDateTime) throws |
|
|
|
UnsupportedOperationException { |
|
|
|
UnsupportedOperationException { |
|
|
|
this(tc, dateFormat, initDateTime, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param tc |
|
|
|
|
|
|
|
* @param dateFormat |
|
|
|
|
|
|
|
* @param initDateTime |
|
|
|
|
|
|
|
* @param initTime 判断是不是要通过insertString设置默认值 |
|
|
|
|
|
|
|
* @throws UnsupportedOperationException |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public JDateDocument(JTextComponent tc, |
|
|
|
|
|
|
|
SimpleDateFormat dateFormat, |
|
|
|
|
|
|
|
String initDateTime, |
|
|
|
|
|
|
|
boolean initTime) throws |
|
|
|
|
|
|
|
UnsupportedOperationException { |
|
|
|
|
|
|
|
//设置当前日期格式
|
|
|
|
//设置当前日期格式
|
|
|
|
setDateFormat(dateFormat); |
|
|
|
setDateFormat(dateFormat); |
|
|
|
//保存操作的文本框
|
|
|
|
//保存操作的文本框
|
|
|
|
textComponent = tc; |
|
|
|
textComponent = tc; |
|
|
|
//设置显示为当前日期,同时完成显示的格式化,如果emptyDateTime为true就设时间为空
|
|
|
|
|
|
|
|
if (!initTime) { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
insertString(0, initDateTime, null); |
|
|
|
insertString(0, initDateTime, null); |
|
|
|
} catch (BadLocationException ex) { |
|
|
|
} catch (BadLocationException ex) { |
|
|
|
throw new UnsupportedOperationException(ex.getMessage()); |
|
|
|
throw new UnsupportedOperationException(ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置当前日期格式 |
|
|
|
* 设置当前日期格式 |
|
|
|
* |
|
|
|
|
|
|
|
* @param dateFormat SimpleDateFormat |
|
|
|
* @param dateFormat SimpleDateFormat |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setDateFormat(SimpleDateFormat dateFormat){ |
|
|
|
public void setDateFormat(SimpleDateFormat dateFormat){ |
|
|
@ -77,7 +56,6 @@ public class JDateDocument extends PlainDocument { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 取得当前日期格式 |
|
|
|
* 取得当前日期格式 |
|
|
|
* |
|
|
|
|
|
|
|
* @return SimpleDateFormat |
|
|
|
* @return SimpleDateFormat |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public SimpleDateFormat getDateFormat(){ |
|
|
|
public SimpleDateFormat getDateFormat(){ |
|
|
@ -86,7 +64,6 @@ public class JDateDocument extends PlainDocument { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 取得当前系统日时 |
|
|
|
* 取得当前系统日时 |
|
|
|
* |
|
|
|
|
|
|
|
* @return String |
|
|
|
* @return String |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static String getCurrentDate(SimpleDateFormat smFormat){ |
|
|
|
public static String getCurrentDate(SimpleDateFormat smFormat){ |
|
|
|