palexdev / MaterialFX

A library of material components for JavaFX
GNU Lesser General Public License v3.0
1.21k stars 122 forks source link

MFXDatePicker (Date Range Limits) #259

Closed PLEUTOSEEK closed 1 year ago

PLEUTOSEEK commented 1 year ago

I would like to ask whether MFXDatePicker could implement a date range limit function, which let the user only able to select defined date range values.

Millions of thanks to author(s).

PLEUTOSEEK commented 1 year ago
this.dtDatePicker.setCellFactory(new Function<>() {
            @Override
            public MFXDateCell apply(LocalDate t) {
                return new MFXDateCell(dtDatePicker, t) {
                    @Override
                    public void updateItem(LocalDate item) {
                        super.updateItem(item);

                        if (item.isBefore(LocalDate.now())) {
                            setDisable(true);
                        } else {
                            setDisable(false);
                        }
                    }
                };

            }
        });

Hey, I think I found the way to solve my issue, thanks.

palexdev commented 1 year ago

Glad to see you found a way Keeping this in mind as an improvement for the future, added to the Improvements list as TBD