public void setSelectedItem(Object anItem) {
   if (anItem == null) {
     return;
   }
   if (anItem instanceof Date) {
     try {
       selectedDate = this.dateFormat.format((Date) anItem);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   } else {
     try {
       String strDate = anItem.toString().trim();
       if (strDate.length() != 10 && strDate.length() != 19) {
         return;
       }
       String pattern = dateFormat.toPattern();
       if (strDate.length() == 10 && pattern.length() == 19) {
         strDate = strDate + selectedDate.substring(10);
       }
       dateFormat.parse(strDate);
       selectedDate = strDate;
     } catch (Exception ex) {
       throw new UnsupportedOperationException(
           "Invalid datetime: string ["
               + anItem
               + "], format is ["
               + dateFormat.toPattern()
               + "]. ");
     }
   }
   fireContentsChanged(this, -1, -1);
 }