I'm using JFXtras CalendarPicker to get dates for multiple days in the calendar. My project is a JavaFX project and I'm using an FXML, in that the CalendarPicker is linked to my Controller class. In details, this is my FXML:
<CalendarPicker fx:id="calendarpicker" mode="MULTIPLE" />
In my controller class, I'm using a EventHandler inside the initialize() method:
public void initialize() {
this.dateFormat = new SimpleDateFormat("yyyy-mm-dd");
calendarpicker.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getButton().equals(MouseButton.PRIMARY)) {
Calendar cal = calendarpicker.getCalendar();
if(cal != null){
String formattedDate = dateFormat.format(cal.getTime());
ObservableList<String> items = listview.getItems();
if (!items.contains(formattedDate)) {
items.add(formattedDate);
} else {
items.remove(formattedDate);
}
listview.setItems(items);
}
}
}
});
}
So in JFXtras the CalendarPicker dates inside the calendar looks like buttons, on one click (you press down the button), but when you release it it doesn't come up. If you click again on the pressed down button it will come up. I have a ListView (named as "listview") what I want to populate with the dates when I click on the calendar day it should add the date to the list. If the date is NOT on the list I want to add it. If it is already on the list (so the button is already pressed down), and I click on it again, it should remove that date from the list.
The problem is that my code doesn't behave as expected, probably because this two stage action (pressing down and pressing again to come up). I have no clue how to fix it, so I kindly ask for help.