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

Using JIDE combo-boxes

Continuing last week’s article on customized combo-boxes (a.k.a. popup menus or drop-downs), today I discuss how we can use JIDE [1]‘s vast array of custom professional combo-boxes in our Matlab GUI.
As I’ve already noted here in several [2] articles, Matlab heavily uses JIDE’s library of GUI controls for its own GUI (Desktop, Editor etc.) and we can tap into this wealth of components in our own GUI. I’ve recently shown an example of this in my treeTable [3] utility, which greatly extends Matlab’s standard uitable. After using treeTable for a while, it’s difficult to go back to using the plain standard uitable… A similar experience will undoubtedly occur after using some of JIDE’s combo-boxes.

DateSpinnerComboBox CheckBoxListComboBox ColorComboBox
Some of the JIDE combo-box controls

JIDE combo-boxes

JIDE’s combo-box controls are generally grouped in the JIDE Grids package and extend the standard Java Swing JComponent (JIDESoft actually found it easier to extend JComponent than JComboBox, but users really have nothing to complain – all the extra functionality and more have simply been reimplemented). The JIDE Grids package is included in each Matlab installation (/java/jarext/jide/jide-grids.jar under the Matlab root). In particular, JIDE Grids includes the com.jidesoft.combobox Java package, which groups the combo-box components. You can find further details on JIDE Grids in the Developer Guide [4] and the Javadoc documentation [5].
Back in 2010, I explained [6] how we can use one of these components, DateComboBox [7], and its close associate DateSpinnerComboBox [8]. Today I extend the coverage to briefly examine JIDE’s other custom combo-box controls.
Each of the following classes has both a combo-box control and a corresponding panel that is presented when the combo-box arrow button is clicked (activated). The panel is normally called xxxChooserPanel and its corresponding combo-box is called xxxComboBox. So, for example, we would have ColorComboBox coupled with ColorChooserPanel. After the combo-box is created, the panel can be accessed and customized via the combo-box’s PopupPanel property or the corresponding getPopupPanel() method. The panel can also be displayed as a standalone control, as I’ve shown in the DateComboBox article [6]. GUI designers can choose whether to use a compact combo-box or the full-size panel control.

Integrating in Matlab GUI

To use any of these controls, we first need to initialize JIDE usage in Matlab, then create an instance of the control, and finally place it onscreen using the semi-documented javacomponent function:

% Initialize JIDE's usage within Matlab
com.mathworks.mwswing.MJUtilities.initJIDE;
% Display a DateChooserPanel
jCombo = javaObjectEDT(com.jidesoft.combobox.DateComboBox);  % javaObjectEDT is optional but advisable
[hjCombo, hContainer] = javacomponent(jCombo, [10,10,100,20], gcf)

Each combo-box control accepts its combo-list elements somewhat differently. For example, for DateComboBox we can specify the acceptable date-range (via DefaultDateModel [27]) and initial date, for a FontComboBox we can specify the initial font, and for any of the list controls we need to specify the list elements (as a cell-array of strings). However, most if not all of these components have default constructors so we can initialize the controls without any inputs and let it automatically use the defaults. For example, the date-selection controls will use the current date (today) as its default value.
In most cases, we can set the control handle’s ActionPerformedCallback to process a selection event (or modification of the combo-box value via direct editing in its integrated editbox):

set(hjCombo, 'ActionPerformedCallback', @myMatlabCallbackFcn);

The selected item can in most cases be retrieved via

selectedItem = get(hjCombo,'SelectedItem');  % or: hjCombo.getselectedItem

For some combo-boxes, non-numeric results may need to be converted into Matlab strings, via the char function:

selectedItem = char(selectedItem);

Next week I plan to present a non-trivial customization of the CheckBoxListComboBox control.
Additional discussion of JIDE’s combo-boxes, and JIDE controls in general, is available in Chapter 5 of my Matlab-Java Programming book [28].
If you need to integrate professional-looking controls such as these in your Matlab GUI, consider hiring my consulting services [29].

Caution

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. In any case, Matlab releases always lag the latest JIDE release by at least a year (e.g., Matlab R2013b uses JIDE v3.4.1 that was released in June 2012). The older your Matlab, the more such inconsistencies that you may find. For example, I believe that DateSpinnerComboBox only became available around R2010b; similarly, some control properties behave differently (or are missing altogether) in different releases. To determine the version of JIDE that you are currently using in Matlab, run the following (the result can then be compared to JIDE’s official change-log history [30]):

>> com.jidesoft.utils.Lm.getProductVersion
ans =
3.4.1

Note that JIDE is a commercial product. We may not use it without JIDESoft’s permission outside the Matlab environment. It is my understanding however, that we can freely use it within Matlab. Note that this is not legal advise as I am an engineer, not a lawyer. If you have any licensing questions, contact sales@jidesoft.com.

2 Comments (Open | Close)

2 Comments To "Using JIDE combo-boxes"

#1 Comment By Steven Tsai On September 3, 2014 @ 02:09

Hi Yair,

I was trying to use a ◾TreeComboBox in my GUI, but it seems something is wrong:

#2 Comment By amir On April 5, 2016 @ 08:20

hi…
1)how can i set string to CheckBoxListComboBox and get index of selected string
2)is other kind calender of DateComboBox related to jalili calender