Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Calendar Button on DatePicker?

Is there a simple way to hide the calendar button on the DatePicker Node in JavaFX? Some of our dates are not editable, and the calendar button is just adding to the width of the field.

like image 325
Tommo Avatar asked May 28 '26 13:05

Tommo


1 Answers

You can use the following css to remove the calendar button

.date-picker > .arrow-button {
    -fx-padding: 0px;
}

.date-picker > .arrow-button > .arrow {
    -fx-padding: 0px;
}

Edit - To get back the right border :

.date-picker > .date-picker-display-node {
    -fx-background-insets: 1 1 1 1;
}

Edit - To apply the above style to only few datepickers

Declare a DatePicker and add a styleclass to it.

DatePicker nonEditableDatePicker = new DatePicker();
nonEditableDatePicker.getStyleClass().add("non-editable-datepicker");

Use this styleclass to add styles :

.non-editable-datepicker > .arrow-button {
    -fx-padding: 0px;
}

.non-editable-datepicker > .arrow-button > .arrow {
    -fx-padding: 0px;
}

.non-editable-datepicker > .date-picker-display-node {
    -fx-background-insets: 1 1 1 1;
}
like image 127
ItachiUchiha Avatar answered Jun 01 '26 13:06

ItachiUchiha