- Undocumented Matlab - http://undocumentedmatlab.com -

Date selection components

Posted By Yair Altman On June 30, 2010 | 70 Comments

Have you ever wondered why Matlab does not have standard GUI date-handling components?
Matlab has many built-in date-handling functions (calendar, date, datestr, datenum, datetick, datevec etc.). Unfortunately, this built-in support does not extend to Matlab GUI. If we need a date-selection drop-down or calendar panel we have to design it ourselves, or use a third-party Java component or ActiveX control.

JIDE Components

Luckily, we have a much better alternative, right within Matlab. This relies on the undocumented fact that Matlab uses JIDE components [1] for many of its GUI components. As already explained earlier [2], JIDE controls are pre-bundled in Matlab (/java/jarext/jide/jide-grids.jar under the Matlab root). You can find further details on JIDE Grids in the Developer Guide [3] (pages 28-35) and the Javadoc documentation [4].
In particular, JIDE Grids includes the following date-selection controls:

  • DateChooserPanel [5] – an extension of Swing’s JPanel that displays a single month and enables selecting one or more days
  • CalendarViewer [6] – a similar panel, that displays several months in a table-format (e.g., 4×3 months)
  • DateComboBox [7] – a combo-box (drop-down/popup menu) that presents a DateChooserPanel for selecting a date
  • DateSpinnerComboBox [8] – presents a date-selection combo-box that includes both the DateComboBox and a spinner control (this control is only available in the latest Matlab releases)
  • MonthChooserPanel [9] – a panel that enables selection of entire months (not specific dates)
  • MonthComboBox [10] – a month selection combo-box, similar to DateComboBox but without the ability to select individual days

Usage of these controls is very similar, so I’ll just show the basics here. First, to present any control, we need to use the built-in javacomponent function or the uicomponent [11] utility:

% Initialize JIDE's usage within Matlab
% Display a DateChooserPanel
jPanel = com.jidesoft.combobox.DateChooserPanel;
[hPanel,hContainer] = javacomponent(jPanel,[10,10,200,200],gcf)

DateChooserPanel   MonthChooserPanel
DateChooserPanel and MonthChooserPanel components

2x2 CalendarViewer component

Just as with any Java object, properties may either be accessed with the Java accessor methods (e.g. getName() or setName(name)), or the Matlab get/set semantics (e.g. get(prop,’Name’) or set(prop,’Name’,value)). When using the Matlab syntax, remember to wrap the Java object in a handle() call, to prevent a memory leak (or use hPanel rather than jPanel):

jPanel.setShowWeekNumbers(false);    % Java syntax
set(hPanel,'ShowTodayButton',true);  % Matlab syntax

Retrieving the selected date is easy:

>> selectedDate = jPanel.getSelectedDate()
selectedDate =
Sun Jun 27 00:00:00 IDT 2010
% or: selectedDate = get(jPanel,'SelectedDate');
% Note: selectedDate is a java.util.Date object:
>> selectedDate.get
	Class = [ (1 by 1) java.lang.Class array]
	Date = [27]
	Day = [0]
	Hours = [0]
	Minutes = [0]
	Month = [5]
	Seconds = [0]
	Time = [1.27759e+012]
	TimezoneOffset = [-180]
	Year = [110]


jModel = hPanel.getSelectionModel;  % a com.jidesoft.combobox.DefaultDateSelectionModel object
>> hPanel.getSelectionModel.getSelectedDates
ans =

And of course we can set a callback for whenever the user modifies the selected date(s):

hModel = handle(hPanel.getSelectionModel, 'CallbackProperties');
set(hPanel, 'ValueChangedCallback', @myCallbackFunction);

For the combo-box (drop-down/popup menus) controls, we obviously need to modify the displayed size (in the javacomponent call) to something much more compact, such as [10,10,100,20]. These components display one of the above panels as their pop-up selection panels. Users can access and customize these panels using the combo-box control’s getPopupPanel() function (or PopupPanel property).

DateComboBox   DateSpinnerComboBox
DateComboBox and DateSpinnerComboBox components

Numerous other customizations are possible with these JIDE components – have fun exploring (my uiinspect utility [12] can be quite handy in this)! Just remember that JIDE evolves with Matlab, and so JIDE’s online documentation, which refers to the latest JIDE version, may be partially inapplicable if you use an old Matlab version. The older your Matlab, the more such inconsistencies that you may find.

Alternative components

There are several alternatives to the JIDE components:
If we have Matlab’s Financial toolbox, we can use the uicalendar [13] function. Unfortunately, this control is not available if you don’t own the expensive Financial toolbox.
If we only target Windows-based platforms, we could use third-party ActiveXes such as the Microsoft Date-and-Time-Picker (MSComCtl2.DTPicker.2), Microsoft MonthView (MSComCtl2.MonthView.2) or the Microsoft Office Calendar (MSCAL.Calendar.7) ActiveX controls. Depending on your installed applications, you may have other similar controls. For example, if you have Symantec’s EndPoint Protection (SEP), you have access to the SEP Date Control (LDDATETIME.LDDateCtrl.1). Of course, these controls will not work on non-Windows platforms, or platforms that do not have these ActiveX controls installed.
We can also use other (non-JIDE) third-party Java controls from places like javashareware.com, swinglabs.org, downloadthat.com, sharewareconnection.com, easyfreeware.com, l2fprod.com, fileheap.com/software/components.html, swing-components.safe-install.com and many others. One specific example is NachoCalendar [14], from SourceForge.com.
Finally, we could use some of the utilities posted on the Matlab File Exchange: uical [15], uisetdate [16], calender [17] (sic) and several others.
In my own biased opinion, none of these alternatives comes close to the ease-of-use and functionality of the JIDE components presented above. What do you think? Please add your comments here [18].

Categories: GUI, Java, Medium risk of breaking in future versions, Undocumented feature

70 Comments (Open | Close)

70 Comments To "Date selection components"

#1 Comment By Mike On October 11, 2010 @ 07:44

Could you please explain how to change the date format of the DateSpinnerComboBox? I poked around with the findjobj tool, but it appears the format must be a java class?

Currently it reads 30/06/10. How would you change it to appear as June 30, 2010?


#2 Comment By Donn Shull On October 12, 2010 @ 08:41

@Mike – you can use the java SimpleDateFormat class:

dateSpinner = com.jidesoft.combobox.DateSpinnerComboBox;
dateFormat = java.text.SimpleDateFormat('MMMMM dd, yyyyy');

#3 Comment By Mike On October 15, 2010 @ 13:41

Thanks, Donn. I appreciate your help.

#4 Comment By Mike On October 20, 2010 @ 10:53

Ok, I’m starting to love them java components in my GUI, but I still dont know anything about java.

How would I initialize a date for the DateComboBox?

#5 Comment By Yair Altman On October 20, 2010 @ 13:55

@Mike – you can use the setDate() function, as follows:

dateSpinner = com.jidesoft.combobox.DateSpinnerComboBox;
myDate = java.util.Date('July 4 1776');

Use my [25] or Matlab’s built-in methodsview function to explore the dozens of available methods.

#6 Comment By Mike On October 21, 2010 @ 09:20

Thanks for your response and your patience. Java syntax is completely new to me, so I have great difficulty reading the doc pages online.

#7 Comment By Gunnar On February 24, 2011 @ 06:05

I inserted the OK button with


Now I want the window to close when I push the OK button.

How can I do that by using callback?

#8 Comment By Yair Altman On February 24, 2011 @ 09:57

@gunnar – there is no easy answer I think. If you wish, I could develop a small function that shows you how to do this – email me.

#9 Comment By Henric On January 4, 2012 @ 06:03

Thank you for posting this!

I created a DateChooserPanel with a ValueChangedCallback assigned to it, but it is not triggered when i change the month. Is there a separate callback for this? uiinspect only shows ValueChangedCallback.

Is there any way to get a callback to trigger when changing the month?

#10 Comment By Yair Altman On January 4, 2012 @ 13:17

@Henric – clicking the month is not an actionable event in DateChooserPanel – only selecting a specific date is actionable. If you wish to select a month, use MonthChooserPanel instead.

#11 Comment By Amy On May 22, 2012 @ 15:37

Hi, Yair,
I’m trying to implement a callback for the selection from a DateSpinnerComboBox. Unfortunately, it does not appear to have a date selection model, as you show in your example. I bought your book, but it has the same info as this web page. I’m assuming this is more complicated, since it it has several components (text field, spinner, and DateChooserPanel). Do I have to create some kind of listener for each component?



#12 Comment By Yair Altman On May 23, 2012 @ 00:25

set(jhDateChooser, 'ItemStateChangedCallback', callback);

#13 Comment By Amy On May 23, 2012 @ 08:19


You are amazing! Thank you! This worked like a champ! Maybe this will go into the next edition of the book? 🙂


#14 Comment By Yair Altman On May 23, 2012 @ 13:48

@Amy – maybe 🙂 I’m not sure at the moment if and when a second edition of my book will be published. A lot will depend on the question of how much will the upcoming Matlab 8 change the Java internals and interfaces.

In the meantime I’ve already started working on an altogether different Matlab programming book, and this is taking up much of my time…

#15 Comment By Carlos On May 29, 2012 @ 09:24

First of all thanks for posting this. I’m trying to add a DateComboBox in my GUI, but I need to be able to make some custom dates non selectable (and if possible also display them in another color).

I think I need to override some of the java code (I found an example in jide forum), but I don’t know if it’s possible in Matlab. If it’s possible, how do I do it?

This is the code I found:

new DateComboBox() {
   protected DateChooserPanel createDateChooserPanel() {
      return new DateChooserPanel(getDateModel(), isShowTodayButton(), isShowNoneButton(), isShowWeekNumbers(), getLocale()) {
         protected void updateDateLabel(JComponent dateLabel, Calendar date, boolean isSelected, boolean isToday, boolean withinCurrentMonth) {
            super.updateDateLabel(dateLabel, date, isSelected, isToday, withinCurrentMonth);
            if (isHoliday(date)) { // take your logic to decide which date you want to change color
               ((JideButton) dateLabel).setBackgroundOfState(ThemePainter.STATE_DEFAULT, Color.gray);

#16 Comment By Yair Altman On May 29, 2012 @ 15:24

@Carlos – I’m not sure you can customize the controls this way. However, I think you can use something similar to this (untested):

jDateChooser = javaObjectEDT(com.jidesoft.combobox.DateComboBox);
calendar = java.util.Calendar.getInstance;
calendar.setTime(java.util.Date(datestr(dateNum)));  %dateNum is your invalid Matlab date

Alternately, you can create a Java class that implements com.jidesoft.combobox.DateFilter. This is a simple interface that just defines 3 methods:

getMaxDate() : java.util.Calendar
getMinDate() : java.util.Calendar
isDateValid(java.util.Calendar) : boolean

Once you compile this class, you can add an object of it to the jDateChooser via


#17 Comment By Carlos On May 30, 2012 @ 02:15

Thanks a lot! It worked and it also changes de color of the non selectable dates to gray.
But the correct method was addInvalidDate instead of removeInvalidDate. removeInvalidDate is for making the invalid date selectable again.
I found out that you can also set a min date and a max selectable date easily with setMaxDate or setMinDate (calling them in the same way that addInvalidDate).

#18 Comment By Carlos On May 30, 2012 @ 02:22

I’ve just seen your edited comment. I want to change the selectable dates during the execution of my program depending on several things so I guess it’d be more simple to just use addInvalidDate, setMinDate and setMaxDate.
Thanks a lot!

#19 Comment By Cesar On July 18, 2012 @ 16:18

It would be possible to show an example in java which display multiple dates selected, for example if the dates are taken from the db and need to be shown on the calendar

#20 Comment By Ivan On October 24, 2012 @ 14:18

Hey Yair, I am following your guide and I ran into a problem.
I did exactly the same as you wrote, and everything was good until the part where i wanted to select
multiple dates on a calendar. But when I type in this line:
jModel = hPanel.getSelectionModel;

It says: “No appropriate method, property, or field getSelectionModel for class handle.handle.”

What am I doing wrong? I’ve tried everything.
Thanks in advance!

#21 Comment By Yair Altman On October 24, 2012 @ 14:41

@Ivan – this means that the hPanel was not created properly, or perhaps was deleted by the time your program got to the jModel assignment line.

#22 Comment By Ivan On October 25, 2012 @ 10:33

So how do I fix that? I followed your guide and used exactly the same commands up to that point.
This would really help me a lot.

#23 Comment By Ivan On October 25, 2012 @ 10:55

When I leave the figure window open and type the lines:

jModel = hPanel.getSelectionModel;

then it doesn’t report the error I mentioned above. But it still doesn’t change the ability to select more dates on a calendar.
I’m confused.

#24 Comment By Yair Altman On October 25, 2012 @ 11:10

@Ivan – it is impossible to know exactly why this happens without debugging your code and knowing more details about your environment (platform, Matlab release, java version – basically what ver reports). Contact me via email (altmany at gmail) with all the details and I’ll send you a proposed quote for solving this.

#25 Comment By Varouj On July 17, 2013 @ 10:27

I am not too clear about how to include this in my own GUI. I have an app for which I created a GUI using GUIDE. How do I embed calendar tools in my GUI?

#26 Comment By Yair Altman On July 17, 2013 @ 17:02

@Varouj – use the [26] function.

#27 Comment By amodedude On August 27, 2013 @ 18:46

This is probably something so obvious that, for 90% of the people here, it may not be worth mentioning. For the sake of people like me that are still learning the absolute basics, I’d like to note that a simple way to make the calender disappear after selecting the desired date is:


Also, a way of getting the date so that you can use it for whatever you may need would be:

% Get the selected date
selectedDate = hModel.getSelectedDate();

% Get Date Values
dayNumber  = get(selectedDate, 'Date');
monthVal   = get(selectedDate, 'Month');
yearVal    = get(selectedDate, 'Year');

#28 Comment By Yair Altman On August 28, 2013 @ 22:53

@amodedude – thanks for taking the time to make this clarification 🙂

#29 Comment By Peter Neilley On October 7, 2013 @ 10:32

I have a MATLAB GUI app that uses the DateChooserPanel. The app works fine on my Windows machines and on most of my Linux machines too. However, on one of my Linux machines, I get the following error when starting the application: “Unauthorized usage of JIDE products. You get this message if you didn’t input a correct license key.” The application runs, and the DateChoosePanel seemingly works other than returning a null date upon click.

The linux box that I have this issue on is running V2.6.18. Another linux box running 2.6.18 runs the application just fine.

I did not install any JIDE products/licenses on any of the machines this application works fine on. I thought JIDE automatically is part of MATLAB and no additional license is necessary.

Any ideas from anyone what’s going on here?

#30 Comment By Yair Altman On October 7, 2013 @ 10:43

@Peter – JIDE is indeed part of Matlab, but sometimes Matlab initializes JIDE after your application, and therefore when it first starts to use JIDE in your app then JIDE complains. You can workaround most of these cases by issuing the following command at the very top of your application:


In rare cases this is not enough, since Matlab’s JIT pre-compiles the application and tries to load the relevant JIDE classes before initJIDE gets called in runtime. The workaround in these cases is to simply use eval to force Matlab to only load these classes in run-time. For example:

jtable = eval('com.jidesoft.grid.GroupTable(model);');  % prevent JIDE alert by run-time (not load-time) evaluation

My recent [27] illustrates both of these workarounds.

#31 Pingback By Using JIDE combo-boxes | Undocumented Matlab On October 16, 2013 @ 06:55

[…] in 2010, I explained how we can use one of these components, DateComboBox, and its close associate DateSpinnerComboBox. […]

#32 Comment By Max On April 27, 2014 @ 03:22

Hi, nice article!
I try to make calendarViewer on my figure. But then i run

f = figure();
jPanel = com.jidesoft.combobox.CalendarViewer();
[hPanel,hContainer] = javacomponent(jPanel,[10,10,200,200],f);

I get calendarViewer, which is not filled. It looks like a 4×3 blue boxes with control arrows.
What I do wrong?
Win 8.1, Matlab R2014a

#33 Comment By Yair Altman On April 27, 2014 @ 03:34

@Max – you can’t expect a full year’s calendar to appear nicely in 190×190 pixels – change the control’s position vector to [10,10,600,600] or larger if you wish to see the internal text

#34 Comment By Max On April 27, 2014 @ 03:51

Sorry, I found the reason of problem. Argument [10,10,200,200] in javacomponent define too small width and height.

#35 Comment By Max On April 27, 2014 @ 03:57

@Yair Altman
thanks a lot. You make my life a bit simpler with JIDE calendarViewer.

#36 Comment By Max On May 4, 2014 @ 05:08

Hi again, Yair.
Is there some way to highlight holidays and colorize background in calendarViewer?

#37 Comment By Marc On September 6, 2014 @ 10:23

I am trying to get a callback when clicking on a date but it returns the error :

Error using javahandle_withcallbacks.com.jidesoft.combobox.DateChooserPanel/set
The name ‘ValueChangedCallback’ is not an accessible property for an instance of class ‘com.jidesoft.combobox.DateChooserPanel’.

Error in ZenRX>date_push_Callback (line 358)
set(hPanel, ‘ValueChangedCallback’, @myCallbackFunction);

Here is my code :

function date_push_Callback(hObject, eventdata, handles)
   % Initialize JIDE's usage within Matlab
   % Display a DateChooserPanel
   jPanel = com.jidesoft.combobox.DateChooserPanel;
   [hPanel,~] = javacomponent(jPanel,[10,250,730,350],gcf);
   set(hPanel, 'ValueChangedCallback', @myCallbackFunction);

function myCallbackFunction()
   hModel = handle(hPanel.getSelectionModel, 'CallbackProperties');
   selectedDate = hModel.getSelectedDate();
   dayNumber  = get(selectedDate, 'Date')

#38 Comment By Yair Altman On September 6, 2014 @ 10:30


#39 Comment By Marc On September 6, 2014 @ 14:51

It still doesn’t work.

I tried :

hPanel = handle(hPanel, 'CallbackProperties')
set(hPanel, 'ValueChangedCallback', @myCallbackFunction);

and I get error :

Error using javahandle_withcallbacks.com.jidesoft.combobox.DateChooserPanel/set
The name ‘ValueChangedCallback’ is not an accessible property for an instance of class ‘com.jidesoft.combobox.DateChooserPanel’.

Error in ZenRX>date_push_Callback (line 359)
set(hPanel, ‘ValueChangedCallback’, @myCallbackFunction);

#40 Comment By Yair Altman On September 6, 2014 @ 23:13

set(hPanel, 'ItemStateChangedCallback', @myCallbackFunction

#41 Comment By Marc On September 7, 2014 @ 02:30

Thank you very much Yair. One last question. I would like to delete the jpanel and not just hide it [ jPanel.setVisible(false) ] like someone mentioned before. Is there a command for that ?

#42 Comment By Yair Altman On September 7, 2014 @ 04:38


#43 Comment By Marc On September 8, 2014 @ 00:41

I tryed:


Error : Warning: File ‘jPanel’ not found.

#44 Comment By Yair Altman On September 8, 2014 @ 01:24

Marc – come on!!!
I wrote hContainer – I did not write ‘jPanel’.

#45 Comment By Simon du Plooy On September 10, 2014 @ 06:40

Hi Yair,

I have create a DateCombobox abnd I am having trouble customizing the PopupPanel using the getPopupPanel method. It appears that the PopupPanel only gets created once the down arrow button is clicked and gets deleted once a date has been clicked, thus I am unable to get the handle and make changes.

For instance if I implement this code:

%Initialize JIDE's usage within Matlab

%Create Date Combobox
jDateChooser = javaObjectEDT(com.jidesoft.combobox.DateComboBox);
[hPanel,hContainer] = javacomponent(jDateChooser,[50,400,200,20],gcf);

% Get handle to PopupPanel

ans = []

An empty matrix is returned, implying the PopupPanel doesn’t exist yet.

However, If I then implement the following code:

% Create font object:
import java.awt.*
fontObj = javax.swing.plaf.FontUIResource('Gill Sans MT',Font.PLAIN, 12);

% Set Font for PopupPanel

The font in the PopupPanel does change, but doesn’t persist until the next instance, implying the PopupPanel got destroyed and recreated.

Lastly, I used your uiinspect tool and noticed the isPopupVolatile method returns true. I tried to change this using the setPopupVolatile method to false, but to no avail.


ans = 1

Any ideas how I can access the PopupPanel of a DateCombobox?

#46 Comment By Yair Altman On September 10, 2014 @ 06:59

@Simon – You could try to trap the object’s PopupMenuWillBecomeVisibleCallback:


Inside the callback function I think that you would get a valid PopupPanel handle (untested)

#47 Comment By Simon du Plooy On September 11, 2014 @ 00:06

Hi Yair,

Thank you. Implementing this code worked perfectly.

function myCallbackFcn(hObject,event)
import java.awt.*
fontObj = javax.swing.plaf.FontUIResource('Gill Sans MT',Font.PLAIN, 12);


#48 Comment By Yair Altman On September 11, 2014 @ 00:09

Even simpler:

function myCallbackFcn(hObject,event)
   jFont = java.awt.Font('Gill Sans MT', java.awt.Font.PLAIN, 12);

#49 Comment By dingchi On October 4, 2014 @ 07:51

Hi Yair,

I have create a DateCombobox and I am having trouble about how to retrieve the selected date.

%Initialize JIDE's usage within Matlab
%Create Date Combobox
jDateChooser = javaObjectEDT(com.jidesoft.combobox.DateComboBox);
[hPanel,hContainer] = javacomponent(jDateChooser,[50,400,200,20],gcf);
% Get handle to PopupPanel
ans = []

#50 Comment By Yair Altman On October 4, 2014 @ 10:20

@dingchi – the popup panel needs to be displayed at least once for the panel to be created. You can do this programmatically:

jDateChooser.showPopup; jDateChooser.hidePopup;  % show and immediately hide the popup panel

ans =

#51 Comment By Emma On December 2, 2014 @ 05:58

Hi Yair,

Maybe I posted to the wrong blog….

Here is the date selection. I want to know is there any function or component can do the hour, minute and second selection?

Sorry..little bit mess up. Thanks

#52 Comment By Yair Altman On December 4, 2014 @ 14:33

@Emma – you can display a time-selector in the date panel using the following code snippet:


There are also the related TimeFormat (default=”) and TimeZone properties that you can set.

If you need to interact with the time-related aspects of the panel, then you will need to investigate this yourself or hire me for a short consulting gig, since it’s beyond the scope of a simple blog comment.

#53 Comment By David M On January 4, 2015 @ 15:29

Hi Yair,

In my application, I have coupled the appearance of a DateChooserPanel with the selection of a pushbutton/calender icon. Here is my issue: the pushbutton is located in the middle of a number of edit/text boxes. As such, when the DateChooserPanel is made visible, it appears on-top of or behind the other objects around it, and stays that way even after I ‘close it’ (i.e. set visible to false). The only way I could figure to make a seamless appearance/disappearance of the DateChooserPanel involves creating and then deleting the java component handle ‘hPanel’ every time the pushbutton is selected. This works, but I was wondering if there was a better way? I have read in normal Java script, I would need to create a JLayeredPane or make use of GlassPane.

#54 Comment By Piyush On November 17, 2015 @ 10:38

I am using this Calendar. I was wondering does this have the functionality to resize itself if you change the screen. It would be great if you help me in this process.

#55 Comment By Yair Altman On November 17, 2015 @ 11:00

You can set the java component’s Matlab container’s Units property to ‘normalized’ in order to automatically resize when the figure resizes:

% Display a DateChooserPanel
jPanel = com.jidesoft.combobox.DateChooserPanel;
[hPanel,hContainer] = javacomponent(jPanel,[10,10,200,200],gcf)

#56 Comment By amir On January 12, 2016 @ 06:02

is there menu for other kind of calenders such as month date (in arabic language) …
or sun date(in nfarsi language)… thanks alot

#57 Comment By Efraim Salari On January 12, 2016 @ 20:53

I only see day 1-9 of the month, all the other days are indicated with three dots (like this …). I work on linux matlab 2015a.

On windows, matlab 2014b it works properly!
Any suggestions?

#58 Comment By Yair Altman On January 12, 2016 @ 21:13

@Efraim – try to enlarge the component so that it has more space to display the 2-digit numbers.

#59 Comment By Efraïm Salari On January 26, 2016 @ 11:35

Works perfect! Thanks for the help.

#60 Comment By Heiko On February 10, 2016 @ 16:35


how to set the default date that Shows up when inititalizing the DateSpinnerComboBox?


#61 Comment By Heiko On February 10, 2016 @ 16:51

… found the solution: SetDate with Java date Format as Input java.util.Date()

#62 Comment By Mikhail On November 2, 2016 @ 10:29

Hi, Yair Altman!
I use this helpful functionality but got interesting problem:

Create calendar this way:

% --- Executes just before AddEditDoc is made visible.
function AddEditDoc_OpeningFcn(hObject, eventdata, handles, varargin)
   % code code code
   handles.jPanel = com.jidesoft.combobox.DateChooserPanel;
   [hPanel,hContainer] = javacomponent(handles.jPanel,[500,130,200,200],gcf);
   handles.hPanel = hPanel;
   handles.output = hObject;
   set(handles.hPanel, 'MousePressedCallback', ...
       @(src, evnt)CellSelectionCallback(src, evnt, handles));
   set(handles.hPanel, 'KeyPressedCallback', ...
       @(src, evnt)CellSelectionCallback(src, evnt, handles));
   guidata(hObject, handles);

And Callback function:

function CellSelectionCallback(hObject, evnt, handles)
   hModel = handle(hObject.getSelectionModel, 'CallbackProperties');
   selectedDate = hModel.getSelectedDate();
   dayNumber = get(selectedDate,'Date');
   handles.edit_text.String = num2str(dayNumber); 
   guidata(handles.figure1, handles);

The problem: if I use Debug mode it works correct (put date day into this edit_text Object) but in normal mode it stays empty.
I thought a lot about some local variables deleted after exiting from function but still can’t figure out it.

Thank you

#63 Comment By Yair Altman On November 2, 2016 @ 15:09

@Mikail – try to add drawnow; pause(0.1) after you call javacomponent.
See [29]

#64 Comment By Mikhail On November 3, 2016 @ 15:44

Yes, that works! Thank you!

#65 Comment By Mohammad On May 4, 2018 @ 13:50

Dear Yair

I have inserted Date selection components into my MATLAB GUI but I do know how I can make a handle for the Date selection components in order to update the date which is selected by user.

Many thanks in advance….

Kind Regards,


#66 Comment By Yair Altman On May 6, 2018 @ 11:59

Mohammad – read the post carefully: I explained near the bottom how you can get the handle and set callbacks to get the user-selected date.

#67 Comment By Mohammad On May 25, 2018 @ 18:09

Dear Yair,

Many thanks for your help….

Kind Regards,

#68 Comment By Alex On June 20, 2018 @ 22:30

Hi Yair,

I noticed that for the DateComboBox, the current date value was outlined in red (by default) and remained that way even when the selection was changed. Is there any way to move that red outline to another initialized date? Also, I wanted to set a selectable date range, was there any way to do that easily (say by greying out non-valid dates)? Thanks in advance for the help!

#69 Comment By Yair Altman On June 21, 2018 @ 16:30

@Alex – You can disable certain dates and date-ranges in the calendar as follows:

jDateChooser = javaObjectEDT(com.jidesoft.combobox.DateComboBox);
jDateModel = jDateChooser.getDateModel;
calendar = java.util.Calendar.getInstance;
jDateModel.setMinDate(calendar);  % and similarly for MaxDate

Similarly, you can use jDateModel.addInvalidDate(calendar) to add specific invalid dates within the relevant min/max dates.

You can set the date chooser to have a different initial (default) date value, but the current date is always marked on the calendar and AFAIK this cannot be avoided.

If you’d like any additional assistance with your Matlab project, please contact me by email for a consulting offer.

#70 Comment By Alex On June 21, 2018 @ 19:06

Thanks so much for your help Yair, code worked perfectly, you’re a life saver.

Article printed from Undocumented Matlab: http://undocumentedmatlab.com

URL to article: http://undocumentedmatlab.com/articles/date-selection-components

URLs in this post:

[1] JIDE components: http://www.jidesoft.com

[2] earlier: http://undocumentedmatlab.com/blog/jide-property-grids/

[3] Developer Guide: http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf

[4] Javadoc documentation: http://www.jidesoft.com/javadoc/

[5] DateChooserPanel: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateChooserPanel.html

[6] CalendarViewer: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/CalendarViewer.html

[7] DateComboBox: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateComboBox.html

[8] DateSpinnerComboBox: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateSpinnerComboBox.html

[9] MonthChooserPanel: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MonthChooserPanel.html

[10] MonthComboBox: http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MonthComboBox.html

[11] uicomponent: http://www.mathworks.com/matlabcentral/fileexchange/14583-uicomponent-expands-uicontrol-to-all-java-classes

[12] uiinspect utility: http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methodspropertiescallbacks-of-an-object

[13] uicalendar: http://www.mathworks.com/access/helpdesk/help/toolbox/finance/uicalendar.html

[14] NachoCalendar: http://nachocalendar.sourceforge.net/

[15] uical: http://www.mathworks.com/matlabcentral/fileexchange/15913-yet-another-calendar

[16] uisetdate: http://www.mathworks.com/matlabcentral/fileexchange/5915-uisetdate

[17] calender: http://www.mathworks.com/matlabcentral/fileexchange/26560-calender

[18] here: #respond

[19] Font selection components : http://undocumentedmatlab.com/articles/font-selection-components

[20] Color selection components : http://undocumentedmatlab.com/articles/color-selection-components

[21] Plot-type selection components : http://undocumentedmatlab.com/articles/plot-type-selection-components

[22] Listbox selection hacks : http://undocumentedmatlab.com/articles/listbox-selection-hacks

[23] Setting status-bar components : http://undocumentedmatlab.com/articles/setting-status-bar-components

[24] Figure toolbar components : http://undocumentedmatlab.com/articles/figure-toolbar-components

[25] : http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object

[26] : http://undocumentedmatlab.com/blog/javacomponent/

[27] : http://undocumentedmatlab.com/blog/treetable/

[28] : http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a

[29] : http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.