2
有没有简单的方法来隐藏JavaFX中的DatePicker节点上的日历按钮?我们的某些日期不可编辑,日历按钮只是增加了字段的宽度。在DatePicker上隐藏日历按钮?
有没有简单的方法来隐藏JavaFX中的DatePicker节点上的日历按钮?我们的某些日期不可编辑,日历按钮只是增加了字段的宽度。在DatePicker上隐藏日历按钮?
您可以使用下面的CSS删除日历按钮
.date-picker > .arrow-button {
-fx-padding: 0px;
}
.date-picker > .arrow-button > .arrow {
-fx-padding: 0px;
}
编辑 - 要返回右边界:
.date-picker > .date-picker-display-node {
-fx-background-insets: 1 1 1 1;
}
编辑 - 要应用以上风格只有几个datepickers
声明一个DatePicker并为其添加一个styleclass。
DatePicker nonEditableDatePicker = new DatePicker();
nonEditableDatePicker.getStyleClass().add("non-editable-datepicker");
使用此styleClass的样式添加:
.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;
}
所以这绝对删除按钮,但它还会删除字段的右边框。 '.date-picker> .arrow-button { -fx-padding:px; } .date-picker> .arrow-button> .arrow { -fx-padding:0px; }' 这稍微好一点,但仍不完美 – Tommo
@Tommo请检查更新的答案。 – ItachiUchiha
你会如何建议有选择地将这种风格应用于特定的DatePickers,因为我显然不希望它适用于应该可编辑的DatePickers。 – Tommo