java - JavaFX 8 DatePicker features -


i start using new javafx 8 control datepicker. in datepicker user experience documentation, stated has couple of cool features have in gui application:

  1. i want change format mm/dd/yyyy dd/mm/yyyy.
  2. i restrict date can selected. user can select today until same day of next year.
  3. display hijri dates besides original ones:

enter image description here

how implement these features? javadoc doesn't them.

here full implementation:

import java.net.url; import java.time.localdate; import java.time.chrono.hijrahchronology; import java.time.format.datetimeformatter; import java.util.resourcebundle; import javafx.application.platform; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.datecell; import javafx.scene.control.datepicker; import javafx.scene.control.label; import javafx.scene.input.mouseevent; import javafx.util.callback; import javafx.util.stringconverter;  /**  *  * @author fouad  */ public class fxmldocumentcontroller implements initializable {     @fxml     private datepicker dpdate;      @override     public void initialize(url url, resourcebundle rb)     {         dpdate.setvalue(localdate.now());         dpdate.setchronology(hijrahchronology.instance);          callback<datepicker, datecell> daycellfactory = dp -> new datecell()         {             @override             public void updateitem(localdate item, boolean empty)             {                 super.updateitem(item, empty);                  if(item.isbefore(localdate.now()) || item.isafter(localdate.now().plusyears(1)))                 {                     setstyle("-fx-background-color: #ffc0cb;");                     platform.runlater(() -> setdisable(true));                      /* when hijri dates shown, setdisable() doesn't work. here workaround */                     //addeventfilter(mouseevent.mouse_clicked, e -> e.consume());                 }             }         };          stringconverter converter = new stringconverter<localdate>()         {             final datetimeformatter dateformatter = datetimeformatter.ofpattern("dd/mm/yyyy");              @override             public string tostring(localdate date)             {                 if(date != null) return dateformatter.format(date);                 else return "";             }              @override             public localdate fromstring(string string)             {                 if(string != null && !string.isempty())                 {                     localdate date = localdate.parse(string, dateformatter);                      if(date.isbefore(localdate.now()) || date.isafter(localdate.now().plusyears(1)))                     {                         return dpdate.getvalue();                     }                     else return date;                 }                 else return null;             }         };          dpdate.setdaycellfactory(daycellfactory);         dpdate.setconverter(converter);         dpdate.setprompttext("dd/mm/yyyy");     }  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -