Matteo
Matteo

Reputation: 327

How to make a disabled DatePicker look like its enabled

Is it possible to have a DatePicker object in JavaFX disabled, looking like an enabled DatePicker?

Or, how to disable the popup window for the selection of the date ?

I tried with:

myDp.setDisable(true);
myDp.setStyle("-fx-background-color: white");

but no other ideas.. any help?

http://s2.postimg.org/5j3s5nxt5/Immaginedp.png

Thanks !!!

Upvotes: 1

Views: 1105

Answers (2)

Matteo
Matteo

Reputation: 327

Solved

I used in my code:

myDp.setDisable(true);
myDp.setStyle(" -fx-opacity: 1.0;"); 
myDp.getEditor().setStyle("-fx-opacity: 1.0;")

when I want that it looks like if it's disabled, while if I want that it looks like if it's disabled:

myDp.setStyle(" -fx-opacity: 0.4;"); 
myDp.getEditor().setStyle("-fx-opacity: 0.4;")

thanks to ItachiUchiha

Upvotes: 1

ItachiUchiha
ItachiUchiha

Reputation: 36722

A single solution can work for both.

Keep your DatePicker disabled and add the following css :

/* For date-picker */
.date-picker:disabled {
     -fx-opacity: 1.0;
}

/* For date-picker textfield */
.date-picker > .date-picker-display-node:disabled {
    -fx-opacity: 1.0;
}

Upvotes: 0

Related Questions