trilogy
trilogy

Reputation: 1795

stop editing of datepicker and combobox fields without disabling them

I'd like to "disable" a datepicker and combobox (dropdown) without "disabling" it. The reason is, is that they grey out and you can't read them properly.

I'd like the same functionality as when you set a Textfield "non-editable":

textField.setEditable(false)

Is there a way I can do this?

Upvotes: 0

Views: 135

Answers (1)

Zephyr
Zephyr

Reputation: 10253

You can disable the DatePicker and then style it to look like normal:

DatePicker datePicker = new DatePicker();
datePicker.setDisable(true);
datePicker.setStyle("-fx-opacity: 1.0");

When you disable a Node, JavaFX sets its opacity to 0.4; you can just set it right back where it came from.

If you are still wanting to allow a user to select a date with the dropdown but not type their own date, just set the editable property:

datePicker.setEditable(false);

Upvotes: 2

Related Questions