SedJ601
SedJ601

Reputation: 13859

How to disable the TextField of a JavaFx DatePicker?

I want to know how to disable the textfield of a JavaFx DatePicker? I was looking for this question and could not find it, so I am posting it.

Upvotes: 6

Views: 5381

Answers (3)

Gísli V.
Gísli V.

Reputation: 69

If you want to disable the textfield and not have it greyed out you can do this:

DatePicker datePicker = new datePicker();
datePicker.getEditor().setDisable(true);
datePicker.getEditor().setOpacity(1);

Upvotes: 2

SimMac
SimMac

Reputation: 499

If you still want the textfield to look normal (not grayed out) but still not editable, you can set the editor not editable:

datePicker.getEditor().setEditable(false);

Upvotes: 6

SedJ601
SedJ601

Reputation: 13859

If you want to disable the DatePicker's textfield you should get the editor and setDisable to true.

DatePicker datePicker = new DatePicker(LocalDate.now());
datePicker.getEditor().setDisable(true);

Upvotes: 3

Related Questions