4

I want to remove the ComboBox of a DatePicker and only show the Calendar of the DatePicker instead.

Explained here: JavaFX extract calendar-popup from DatePicker / only show popup

If I want to accomplish it in java I would do something like:

DatePickerSkin skin = new DatePickerSkin(new DatePicker());
Node calendarControl = skin.getPopupContent();

But how can I do this in FXML? (I use SceneBuilder)

<DatePicker id="datePicker" prefHeight="25.0" prefWidth="535.0" showWeekNumbers="true">
  <HBox.margin>
      <Insets left="10.0" right="10.0" top="10.0" />
  </HBox.margin>
</DatePicker>

?

Community
  • 1
  • 1
7twenty7
  • 558
  • 1
  • 3
  • 16

1 Answers1

1

You can try it like this:

<DatePicker id="datePicker" prefHeight="25.0" prefWidth="535.0" showWeekNumbers="true" stylesheets="@yourCSS.css">
  <HBox.margin>
      <Insets left="10.0" right="10.0" top="10.0" />
  </HBox.margin>
</DatePicker>

And yourCSS.css (in the same directory probably):

.date-picker-popup .month-year-pane {
    visibility: hidden;
}

I tried to do it with inline css styles with the attribute style on the DatePicker element, but I didnt get it to work.

EDIT:

Got the question wrong. Im pretty sure you cant display the popup without the combobox of the Datepicker with FXML only.

NDY
  • 3,527
  • 4
  • 48
  • 63
  • I'm not sure if you got the question right. I only want to show the popup and not the ComboBox of the DatePicker. Wouldn't your solution not hide the popup? However I tried your solution but I see no difference in the behavior. – 7twenty7 Apr 20 '16 at 11:39
  • Okay. Got the question wrong. Need to try it out :) – NDY Apr 20 '16 at 11:41
  • @7twenty7 Im pretty sure you cant do it with FXML only. I tried some things out but it didnt work. But probably someone else comes up with another idea. – NDY Apr 20 '16 at 11:57