Created
December 2, 2015 07:18
-
-
Save seungdols/94adddbb201a78f39f57 to your computer and use it in GitHub Desktop.
JavaFX - Use DatePicker custom "format"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Project_formController implements Initializable, LimitText { | |
private static final Logger logger = LoggerFactory.getLogger(Project_formController.class); | |
@FXML | |
private TextField tf_projNM; | |
@FXML | |
private DatePicker proj_SDT; | |
@FXML | |
private DatePicker proj_EDT; | |
@FXML | |
private TextField tf_status; | |
@FXML | |
private Button btn_ok; | |
@FXML | |
private Button btn_reset; | |
@FXML | |
private TextArea ta_desc; | |
private String uid; | |
public void setUid(String uid) { | |
this.uid = uid; | |
} | |
public String getUid() { | |
return uid; | |
} | |
@FXML | |
public void storeAction(ActionEvent event) { | |
try { | |
createProjectInfo(); | |
} catch (Exception e) { | |
logger.debug("store Action================"); | |
e.printStackTrace(); | |
} | |
} | |
@FXML | |
public void clearAction(ActionEvent event) { | |
try { | |
clearText(); | |
} catch (Exception e) { | |
logger.debug("clearAction=================="); | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void initialize(URL location, ResourceBundle resources) { | |
setDatePicker(proj_SDT); | |
setDatePicker(proj_EDT); | |
} | |
public static void setDatePicker(DatePicker picker) { | |
String pattern = "yyyyMMdd"; | |
picker.setPromptText(pattern.toLowerCase()); | |
picker.setConverter(new StringConverter<LocalDate>() { | |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern); | |
@Override | |
public String toString(LocalDate date) { | |
if (date != null) | |
return dateTimeFormatter.format(date); | |
else { | |
return ""; | |
} | |
} | |
@Override | |
public LocalDate fromString(String string) { | |
if (string != null && !string.isEmpty()) { | |
return LocalDate.parse(string, dateTimeFormatter); | |
} else { | |
return null; | |
} | |
} | |
}); | |
picker.setEditable(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment