Class Calendar

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public class Calendar extends Widget implements Accessible, Buildable, ConstraintTarget

Displays a Gregorian calendar, one month at a time.

An example GtkCalendar

A GtkCalendar can be created with Calendar().

The selected date can be retrieved from a GtkCalendar using getDate(). It can be altered with setDate(DateTime).

To place a visual marker on a particular day, use markDay(int) and to remove the marker, unmarkDay(int). Alternative, all marks can be cleared with clearMarks().

Users should be aware that, although the Gregorian calendar is the legal calendar in most countries, it was adopted progressively between 1582 and 1929. Display before these dates is likely to be historically incorrect.

Shortcuts and Gestures

GtkCalendar supports the following gestures:

  • Scrolling up or down will switch to the previous or next month.
  • Date strings can be dropped for setting the current day.

CSS nodes

calendar.view
├── header
│   ├── button
│   ├── stack.month
│   ├── button
│   ├── button
│   ├── label.year
│   ╰── button
╰── grid
    ╰── label[.day-name][.week-number][.day-number][.other-month][.today]

GtkCalendar has a main node with name calendar. It contains a subnode called header containing the widgets for switching between years and months.

The grid subnode contains all day labels, including week numbers on the left (marked with the .week-number css class) and day names on top (marked with the .day-name css class).

Day labels that belong to the previous or next month get the .other-month style class. The label of the current day get the .today style class.

Marked day labels get the :selected state assigned.

  • Constructor Details

    • Calendar

      public Calendar(MemorySegment address)
      Create a Calendar instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Calendar

      public Calendar()
      Create a new Calendar.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Calendar class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Calendar asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • clearMarks

      public void clearMarks()
      Remove all visual markers.
    • getDate

      public DateTime getDate()

      Returns a GDateTime representing the shown year, month and the selected day.

      The returned date is in the local time zone.

      Returns:
      the GDateTime representing the selected date
    • getDay

      public int getDay()
      Gets the day of the selected date.
      Returns:
      the day of the selected date.
      Since:
      4.14
    • getDayIsMarked

      public boolean getDayIsMarked(int day)
      Returns if the day of the this Calendar is already marked.
      Parameters:
      day - the day number between 1 and 31.
      Returns:
      whether the day is marked.
    • getMonth

      public int getMonth()
      Gets the month of the selected date.
      Returns:
      The month of the selected date (as a number between 0 and 11).
      Since:
      4.14
    • getShowDayNames

      public boolean getShowDayNames()

      Returns whether this Calendar is currently showing the names of the week days.

      This is the value of the Gtk.Calendar:show-day-names property.

      Returns:
      Whether the calendar shows day names.
    • getShowHeading

      public boolean getShowHeading()

      Returns whether this Calendar is currently showing the heading.

      This is the value of the Gtk.Calendar:show-heading property.

      Returns:
      Whether the calendar is showing a heading.
    • getShowWeekNumbers

      public boolean getShowWeekNumbers()

      Returns whether this Calendar is showing week numbers right now.

      This is the value of the Gtk.Calendar:show-week-numbers property.

      Returns:
      Whether the calendar is showing week numbers.
    • getYear

      public int getYear()
      Gets the year of the selected date.
      Returns:
      the year of the selected date.
      Since:
      4.14
    • markDay

      public void markDay(int day)
      Places a visual marker on a particular day of the current month.
      Parameters:
      day - the day number to mark between 1 and 31.
    • selectDay

      @Deprecated public void selectDay(DateTime date)
      Deprecated.
      Use setDate(DateTime) instead.
      Switches to date's year and month and select its day.
      Parameters:
      date - a GDateTime representing the day to select
    • setDate

      public void setDate(DateTime date)
      Switches to date's year and month and selects its day.
      Parameters:
      date - a GDateTime representing the day to select
      Since:
      4.20
    • setDay

      public void setDay(int day)

      Sets the day for the selected date.

      The new date must be valid. For example, setting the day to 31 when the month is February will fail.

      Parameters:
      day - The desired day for the selected date (as a number between 1 and 31).
      Since:
      4.14
    • setMonth

      public void setMonth(int month)

      Sets the month for the selected date.

      The new date must be valid. For example, setting the month to 1 (February) when the day is 31 will fail.

      Parameters:
      month - The desired month for the selected date (as a number between 0 and 11).
      Since:
      4.14
    • setShowDayNames

      public void setShowDayNames(boolean value)
      Sets whether the calendar shows day names.
      Parameters:
      value - Whether to show day names above the day numbers
    • setShowHeading

      public void setShowHeading(boolean value)

      Sets whether the calendar should show a heading.

      The heading contains the current year and month as well as buttons for changing both.

      Parameters:
      value - Whether to show the heading in the calendar
    • setShowWeekNumbers

      public void setShowWeekNumbers(boolean value)
      Sets whether week numbers are shown in the calendar.
      Parameters:
      value - whether to show week numbers alongside the days
    • setYear

      public void setYear(int year)

      Sets the year for the selected date.

      The new date must be valid. For example, setting the year to 2023 when the date is February 29 will fail.

      Parameters:
      year - The desired year for the selected date (within GLib.DateTime limits, i.e. from 0001 to 9999).
      Since:
      4.14
    • unmarkDay

      public void unmarkDay(int day)
      Removes the visual marker from a particular day.
      Parameters:
      day - the day number to unmark between 1 and 31.
    • onDaySelected

      Emitted when the user selects a day.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDaySelected

      public void emitDaySelected()
      Emits the "day-selected" signal. See onDaySelected(Calendar.DaySelectedCallback).
    • onNextMonth

      Emitted when the user switches to the next month.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitNextMonth

      public void emitNextMonth()
      Emits the "next-month" signal. See onNextMonth(Calendar.NextMonthCallback).
    • onNextYear

      Emitted when user switches to the next year.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitNextYear

      public void emitNextYear()
      Emits the "next-year" signal. See onNextYear(Calendar.NextYearCallback).
    • onPrevMonth

      Emitted when the user switches to the previous month.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPrevMonth

      public void emitPrevMonth()
      Emits the "prev-month" signal. See onPrevMonth(Calendar.PrevMonthCallback).
    • onPrevYear

      Emitted when user switches to the previous year.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPrevYear

      public void emitPrevYear()
      Emits the "prev-year" signal. See onPrevYear(Calendar.PrevYearCallback).
    • builder

      public static Calendar.Builder<? extends Calendar.Builder> builder()
      A Calendar.Builder object constructs a Calendar with the specified properties. Use the various set...() methods to set properties, and finish construction with Calendar.Builder.build().
      Returns:
      the builder object