Class Calendar
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
GtkCalendar
is a widget that displays a Gregorian calendar, one month
at a time.
A GtkCalendar
can be created with Calendar()
.
The date that is currently displayed can be altered with
selectDay(org.gnome.glib.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()
.
The selected date can be retrieved from a GtkCalendar
using
getDate()
.
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Calendar.Builder<B extends Calendar.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theDaySelectedCallback
callback.static interface
Functional interface declaration of theNextMonthCallback
callback.static interface
Functional interface declaration of theNextYearCallback
callback.static interface
Functional interface declaration of thePrevMonthCallback
callback.static interface
Functional interface declaration of thePrevYearCallback
callback.Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.WidgetClass, Widget.WidgetImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Constructor Summary
ConstructorDescriptionCalendar()
Creates a new calendar, with the current date being selected.Calendar
(MemorySegment address) Create a Calendar proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Calendar
asParent()
Returns this instance as if it were its parent type.static Calendar.Builder
<? extends Calendar.Builder> builder()
ACalendar.Builder
object constructs aCalendar
with the specified properties.void
Remove all visual markers.void
Emits the "day-selected" signal.void
Emits the "next-month" signal.void
Emits the "next-year" signal.void
Emits the "prev-month" signal.void
Emits the "prev-year" signal.getDate()
Returns aGDateTime
representing the shown year, month and the selected day.int
getDay()
Gets the day of the selected date.boolean
getDayIsMarked
(int day) Returns if theday
of the this Calendar is already marked.int
getMonth()
Gets the month of the selected date.boolean
Returns whether this Calendar is currently showing the names of the week days.boolean
Returns whether this Calendar is currently showing the heading.boolean
Returns whether this Calendar is showing week numbers right now.static Type
getType()
Get the GType of the Calendar classint
getYear()
Gets the year of the selected date.void
markDay
(int day) Places a visual marker on a particular day of the current month.Emitted when the user selects a day.onNextMonth
(Calendar.NextMonthCallback handler) Emitted when the user switched to the next month.onNextYear
(Calendar.NextYearCallback handler) Emitted when user switched to the next year.onPrevMonth
(Calendar.PrevMonthCallback handler) Emitted when the user switched to the previous month.onPrevYear
(Calendar.PrevYearCallback handler) Emitted when user switched to the previous year.void
Switches todate
's year and month and select its day.void
setDay
(int day) Sets the day for the selected date.void
setMonth
(int month) Sets the month for the selected date.void
setShowDayNames
(boolean value) Sets whether the calendar shows day names.void
setShowHeading
(boolean value) Sets whether the calendar should show a heading.void
setShowWeekNumbers
(boolean value) Sets whether week numbers are shown in the calendar.void
setYear
(int year) Sets the year for the selected date.void
unmarkDay
(int day) Removes the visual marker from a particular day.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlags
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updateProperty, updateRelation, updateState
Methods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
Calendar
Create a Calendar proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Calendar
public Calendar()Creates a new calendar, with the current date being selected.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
clearMarks
public void clearMarks()Remove all visual markers. -
getDate
Returns aGDateTime
representing the shown year, month and the selected day.The returned date is in the local time zone.
- Returns:
- the
GDateTime
representing the shown date
-
getDay
public int getDay()Gets the day of the selected date.- Returns:
- the day of the selected date.
-
getDayIsMarked
public boolean getDayIsMarked(int day) Returns if theday
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).
-
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.
-
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
Switches todate
's year and month and select its day.- Parameters:
date
- aGDateTime
representing the day to select
-
setDay
public void setDay(int day) Sets the day for the selected date.The new date must be valid. For example, setting 31 for the day when the month is February, fails.
- Parameters:
day
- The desired day for the selected date (as a number between 1 and 31).
-
setMonth
public void setMonth(int month) Sets the month for the selected date.The new date must be valid. For example, setting 1 (February) for the month when the day is 31, fails.
- Parameters:
month
- The desired month for the selected date (as a number between 0 and 11).
-
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 on the left of the days
-
setYear
public void setYear(int year) Sets the year for the selected date.The new date must be valid. For example, setting 2023 for the year when then the date is 2024-02-29, fails.
- Parameters:
year
- The desired year for the selected date (withinGLib.DateTime
limits, i.e. from 0001 to 9999).
-
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
public SignalConnection<Calendar.DaySelectedCallback> onDaySelected(Calendar.DaySelectedCallback handler) 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. SeeonDaySelected(org.gnome.gtk.Calendar.DaySelectedCallback)
. -
onNextMonth
Emitted when the user switched 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. SeeonNextMonth(org.gnome.gtk.Calendar.NextMonthCallback)
. -
onNextYear
Emitted when user switched 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. SeeonNextYear(org.gnome.gtk.Calendar.NextYearCallback)
. -
onPrevMonth
Emitted when the user switched 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. SeeonPrevMonth(org.gnome.gtk.Calendar.PrevMonthCallback)
. -
onPrevYear
Emitted when user switched 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. SeeonPrevYear(org.gnome.gtk.Calendar.PrevYearCallback)
. -
builder
ACalendar.Builder
object constructs aCalendar
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCalendar.Builder.build()
.
-