Below is the Java version of the DateTimePicker control, slightly improved.
This code is now part of TornadoFX Controls , and you can see the latest version of DateTimePicker.java in the GitHub registry. Management is also available in Maven Central and in these coordinates:
<dependency> <groupId>no.tornado</groupId> <artifactId>tornadofx-controls</artifactId> <version>1.0.3</version> </dependency>
Implementation right now:
import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.control.DatePicker; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.util.StringConverter; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; @SuppressWarnings("unused") public class DateTimePicker extends DatePicker { public static final String DefaultFormat = "yyyy-MM-dd HH:mm"; private DateTimeFormatter formatter; private ObjectProperty<LocalDateTime> dateTimeValue = new SimpleObjectProperty<>(LocalDateTime.now()); private ObjectProperty<String> format = new SimpleObjectProperty<String>() { public void set(String newValue) { super.set(newValue); formatter = DateTimeFormatter.ofPattern(newValue); } }; public DateTimePicker() { getStyleClass().add("datetime-picker"); setFormat(DefaultFormat); setConverter(new InternalConverter());
The dateTimeValue property contains a value over time, and valueProperty contains only a date value.
I have not added tests for this component yet, so the implementation may change, check out GitHub for the latest version.
source share