https://github.com/evgen2sat/jfxcalendar
JavaFX Calendar with additional functions
https://github.com/evgen2sat/jfxcalendar
calendar javafx javafx-calendar javafx-components javafx-library
Last synced: 2 months ago
JSON representation
JavaFX Calendar with additional functions
- Host: GitHub
- URL: https://github.com/evgen2sat/jfxcalendar
- Owner: Evgen2sat
- License: bsd-3-clause
- Created: 2022-09-06T06:17:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-07T10:50:16.000Z (over 2 years ago)
- Last Synced: 2025-03-14T06:12:47.804Z (2 months ago)
- Topics: calendar, javafx, javafx-calendar, javafx-components, javafx-library
- Language: Java
- Homepage:
- Size: 70.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JFXCalendar
JavaFX Calendar with additional functions# Description
**JFXCalendar** is a simple JavaFX calendar that allows you to set/get data in the calendar,
set the start day of the week (Monday by default) and set weekend days (Saturday and Sunday by default).# Before use
The calendar style uses the `-primary-color` variable, which is not defined in this project.
`-primary-color` is used for selected days and days that have data. To display styles
it is correct to create a `css` that defines this variable and set it to a direct value.For example, let's create a file, `colors.css` and put it in resources:
```
* {
-primary-color: #1976D2;
}
```Let's add this style to our calendar:
```
JFXCalendar calendar = new JFXCalendar<>();
calendar.getStylesheets().add(JFXCalendar.class.getResource("/colors.css").toExternalForm());
```In the following sections, the addition of `css` is omitted and assumes that you have added it.
# Get started
Create a **JFXCalendar** object and you're done.In this example, we will create a **JFXCalendar** in which the data will be of the String type.
```
JFXCalendar calendar = new JFXCalendar<>();
```If you use the default constructor, then the month displayed in the calendar will be taken from the current date.

Of course, you can use another constructor and pass in the desired month and year.
```
JFXCalendar calendar = new JFXCalendar<>(Month.OCTOBER, 2023);
```
# Set data
You can set data for specific days, and the days will be marked.```
JFXCalendar calendar = new JFXCalendar<>();
List> data = new ArrayList<>();
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 1), "data1"));
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 2), "data2"));
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 3), "data3"));
calendar.setData(data);
```
# Get data
You can get the data set on a specific day.```
JFXCalendar calendar = new JFXCalendar<>();
List> data = new ArrayList<>();
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 1), "data1"));
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 2), "data2"));
data.add(new JFXCalendarData<>(LocalDate.of(2022, 9, 3), "data3"));
calendar.setData(data);
Optional> data1 = calendarView.getData(LocalDate.of(2022, 9, 1));
```# Set start day of week
The default start of the week is Monday, but this can be configured.```
JFXCalendar calendar = new JFXCalendar<>();
calendar.setStartDayOfWeek(DayOfWeek.WEDNESDAY);
```
# Set weekends
By default, Saturday and Sunday are set as holidays, but this can be configured.```
JFXCalendar calendar = new JFXCalendar<>();
calendar.setWeekends(DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY);
```
# Set multiple selection
By default, only one day can be selected by clicking on it, but multiple selection can be enabled.```
JFXCalendar calendar = new JFXCalendar<>();
calendar.setMultipleSelection(true);
```
# Edit year
To change the year, you must click on it, enter new data and press **Enter** to apply the changes
or press **Esc** to cancel changes.
# Get selected dates
To get the selected days, you need to call the `getSelectedDates` method.```
JFXCalendar calendar = new JFXCalendar<>();
Set selectedDates = calendar.getSelectedDates();
```# Listen selected day
To subscribe to the change event of the selected day:```
JFXCalendar calendar = new JFXCalendar<>();
calendar.selectedDateProperty().addListener((observable, oldValue, newValue) -> {
// code
});
```# Listen selected year
To subscribe to the change event of the selected year:```
JFXCalendar calendar = new JFXCalendar<>();
calendar.selectedYearProperty().addListener((observable, oldValue, newValue) -> {
// code
});
```# Listen selected month
To subscribe to the change event of the selected month:```
JFXCalendar calendar = new JFXCalendar<>();
calendar.selectedMonthProperty().addListener((observable, oldValue, newValue) -> {
// code
});
```**Please note** that `LocalDate` is used as the value,
since it is necessary to know not only the month, but also the year, and the day will always be 1.