Search code examples
javafxtextfielddatapicker

JavaFX how to edit a DatePicker make changing the DatePicker Value?


I have a DatePicker and an OnAction Handler that perform different works depending on the value of the DatePicker,the date I have to enter is a birthday date and I have to make some work if it is a date of birth of an adult and some other work if it is a date of birth of an underage. When I change the date using the "Date Picker Menu" my handler correctly perform the work i need , but when i edit TextField the handler not even reacts like DatePicker doesn't acknowledge of this change. How can i make DatePicker "listening" to edit date using TextField?


Solution

  • You can listen to an editor of your DatePicker object:

    myDatePicker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
        // do something
    });
    

    Note, it will be triggered on each typed symbol.