Skip to content

Commit 79e7dbf

Browse files
javier-godoypaodb
authored andcommitted
feat: add yearMonth setter
Close #13
1 parent 37bb4cb commit 79e7dbf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/flowingcode/addons/ycalendar/MonthCalendar.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public MonthCalendar(int year, Month month) {
5050

5151
/** Creates a new instance of {@code MonthCalendar} for the given year-and-month. */
5252
public MonthCalendar(YearMonth yearMonth) {
53-
this.yearMonth = Objects.requireNonNull(yearMonth);
54-
String script = "this.month=new Date($0,$1-1,1);";
55-
getElement().executeJs(script, yearMonth.getYear(), yearMonth.getMonthValue());
53+
setYearMonth(yearMonth);
5654
}
5755

5856
public void setReadOnly(boolean readOnly) {
@@ -69,6 +67,15 @@ public Month getMonth() {
6967
return yearMonth.getMonth();
7068
}
7169

70+
/** Sets the year-and-month that is displayed in this calendar. */
71+
public void setYearMonth(YearMonth yearMonth) {
72+
this.yearMonth = Objects.requireNonNull(yearMonth);
73+
this.yearMonth = Objects.requireNonNull(yearMonth);
74+
String script = "this.month=new Date($0,$1-1,1);";
75+
getElement().executeJs(script, yearMonth.getYear(), yearMonth.getMonthValue());
76+
refreshAll();
77+
}
78+
7279
/**
7380
* Sets the function that is used for generating CSS class names for rows in this calendar.
7481
* Returning {@code null} from the generator results in no custom class name being set. Multiple

0 commit comments

Comments
 (0)