Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 17 days 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: 2024-11-19T21:32:42.655Z (3 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.
![Default constructor](https://i.imgur.com/qSwO1Ta.png)
Of course, you can use another constructor and pass in the desired month and year.
```
JFXCalendar calendar = new JFXCalendar<>(Month.OCTOBER, 2023);
```![Constructor with month and year](https://i.imgur.com/qAd2LA4.png)
# 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);
```![Set data](https://i.imgur.com/NGgrB44.png)
# 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 start day of week](https://i.imgur.com/VkpMXtV.png)
# 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 weekends](https://i.imgur.com/n77wvKM.png)
# 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);
```![Set multiple selection](https://i.imgur.com/svlhg4t.png)
# 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.![Edit year](https://i.imgur.com/miKPIDT.png)
# 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.