<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JIDE &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/jide/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 31 Jan 2018 16:16:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>IP address input control</title>
		<link>https://undocumentedmatlab.com/articles/ip-address-input-control?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ip-address-input-control</link>
					<comments>https://undocumentedmatlab.com/articles/ip-address-input-control#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 31 Jan 2018 16:16:12 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[JIDE]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7313</guid>

					<description><![CDATA[<p>A built-in JIDE control can be used in Matlab GUI for IP-address entry/display. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ip-address-input-control">IP address input control</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editbox-data-input-validation" rel="bookmark" title="Editbox data input validation">Editbox data input validation </a> <small>Undocumented features of Matlab editbox uicontrols enable immediate user-input data validation...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/ishghandle-undocumented-input-parameter" rel="bookmark" title="ishghandle&#039;s undocumented input parameter">ishghandle&#039;s undocumented input parameter </a> <small>The built-in function ishghandle accepts a second input argument with the expected handle type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few weeks ago, a user posted <a href="https://www.mathworks.com/matlabcentral/answers/375588-get-ip-address-over-a-edit-box" rel="nofollow" target="_blank">a question on Matlab Answers</a>, asking whether it is possible to implement a text input control that accepts and validates an IP address (for example, &#8216;192.168.1.101&#8217;). While doing this using purely documented Matlab code is indeed possible (for those of us who are masochistically inclined and/or have nothing else to do with their spare time), a very simple-to-use and polished-looking solution is to use an undocumented built-in Matlab control.<br />
The solution is based on the fact that Matlab comes with a huge set of professional Java-based controls by JideSoft, bundled in various JAR libraries within the <i>%matlabroot%/java/jarext/jide</i> Matlab installation folder. For our specific purposes (an IP-address entry/display control), we are interested in the <code>com.jidesoft.field.IPTextField</code> control (<a href="http://www.jidesoft.com/javadoc/com/jidesoft/field/IPTextField.html" rel="nofollow" target="_blank">online documentation</a>), which is part of the JIDE Grids library (<i>%matlabroot%/java/jarext/jide/jide-grids.jar</i>). We can use it as follows:</p>
<pre lang="matlab">
jIPField = com.jidesoft.field.IPTextField('255.255.255.0');  % set default IP
[jIPField, hContainer] = javacomponent(jIPField, [10,10,120,20], hParent);  % hParent: panel/figure handle
</pre>
<p><center><figure style="width: 193px" class="wp-caption aligncenter"><img decoding="async" src="https://undocumentedmatlab.com/images/IPTextField.png" alt="IPTextField control in a Matlab GUI" title="IPTextField control in a Matlab GUI" width="193" height="84" /><figcaption class="wp-caption-text">IPTextField control in a Matlab GUI</figcaption></figure></center><br />
You can modify the position/size of the text-field in the <i><b>javacomponent</b></i> call above, or by modifying the <b>Position</b> / <b>Units</b> properties of the returned <code>hContainer</code>.<br />
We can retrieve the IP text/numeric values using:</p>
<pre lang="matlab">
vals = jIPField.getValue';         % 1x4 uint32 array => [255,255,255,0]
vals = cell(jIPField.getRawText)'; % 1x4 string cells => {'255','255','255','0'}
ip   = char(jIPField.getText);     % entire IP string => '255.255.255.0'
</pre>
<p>The <code>IPTextField</code> component auto-validates the IP values, ensuring that the displayed IP is always valid (for example, IP components cannot be negative or larger than 255). The component has many other features, including the ability to enable/disable, color or format the IP components etc.<br />
<span id="more-7313"></span><br />
We can set a callback function to process user changes, by setting the component&#8217;s *StateChangedCallback* property, for example:</p>
<pre lang="matlab">jIPField.StateChangedCallback = @(jComponent,jEventData) disp(jComponent.getValue');</pre>
<p>The JIDE libraries that come with Matlab contain numerous other similarly-useful components, including <a href="/articles/using-jide-combo-boxes" target="_blank">date/time/font/color/file/folder selectors</a>, <a href="/articles/date-selection-components" target="_blank">calendars in various formats</a>, credit-card fields, and many more.<br />
For more information about using the <a href="/articles/javacomponent" target="_blank"><i><b>javacomponent</b></i> function</a> and handling Java components in Matlab GUI, see other posts on this website &#8211; particularly those marked with the <a href="/articles/tag/jide" target="_blank">&#8220;JIDE&#8221; tag</a>.<br />
Additional discussion of JIDE&#8217;s combo-boxes, and JIDE controls in general, is available in Chapter 5 of my <a target="_blank" href="/books/matlab-java">Matlab-Java Programming book</a>.<br />
If you need to integrate professional-looking controls such as these in your Matlab GUI, consider hiring my <a target="_blank" href="/consulting/">consulting services</a>.</p>
<h3 id="Caution">Caution</h3>
<p>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 R2017b still uses JIDE v3.4.1 that was released in June 2012 &#8211; MathWorks used to update the bundled JIDE libraries to newer versions, but for some reason has stopped doing that in 2013). The older your Matlab, the more such inconsistencies that you may find. For example, I believe that <code>DateSpinnerComboBox</code> 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&#8217;s official <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/history/">change-log history</a>):</p>
<pre lang='matlab'>
>> com.jidesoft.utils.Lm.getProductVersion
ans =
3.4.1
</pre>
<p>Note that JIDE is a commercial product. We may not use it without JIDESoft&#8217;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.<br />
Also note that all of JIDE&#8217;s controls use the Java-based figures (that are created using GUIDE or the <i><b>figure</b></i> function), and will not work on the new web-based uifigures (created using App Designer or the <i><b>uifigure</b></i> function). There is currently no corresponding IP entry/display control for web-based GUIs, and since there is [still] no way to integrate external Javascript/CSS libraries in uifigures, the only resort is to use a plain-vanilla edit-box. If MathWorks would simply open a hook to integrate external JS/CSS libraries, that would enable users to use 3rd-party libraries that have such custom controls and MathWorks would then not need to spend a huge amount of effort to develop multiple UI control variants.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ip-address-input-control">IP address input control</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editbox-data-input-validation" rel="bookmark" title="Editbox data input validation">Editbox data input validation </a> <small>Undocumented features of Matlab editbox uicontrols enable immediate user-input data validation...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/ishghandle-undocumented-input-parameter" rel="bookmark" title="ishghandle&#039;s undocumented input parameter">ishghandle&#039;s undocumented input parameter </a> <small>The built-in function ishghandle accepts a second input argument with the expected handle type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/ip-address-input-control/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</title>
		<link>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-gui-training-seminars-zurich-29-30-august-2017</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 04 Aug 2017 09:37:52 +0000</pubDate>
				<category><![CDATA[Public presentation]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6992</guid>

					<description><![CDATA[<p>Advanced Matlab training courses on Matlab User Interfaces (GUI) will be presented in Zurich Switzerland on 29-30 August, 2017</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><span class="alignright"><img fetchpriority="high" decoding="async" alt="Advanced Matlab training, Zurich 29-30 August 2017" src="https://undocumentedmatlab.com/images/20140520_153734a_500x321.jpg" title="Advanced Matlab training, Zurich 29-30 August 2017" width="400" height="257"/></span><br />
Advanced Matlab training courses/seminars will be presented by me (Yair) in Zürich, Switzerland on 29-30 August, 2017:</p>
<ul>
<li>August 29 (full day) &#8211; <b>Interactive Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --></p>
<li>August 30 (full day) &#8211; <b>Advanced Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --><br />
	<!-- li>Enroll to both courses (2 full days) for a total price of US$699 (CHF 680.-)</li --> <!-- ($150 extra discount if paid by July 31) -->
</ul>
<p><!-- b>Both seminars are confirmed</b>: they do not depend on a minimal number of participants. But there is a limit on the total number of participants, so the sooner you enroll, the more likely you are to get a seat. --><br />
The seminars are targeted at Matlab users who wish to improve their program&#8217;s usability and professional appearance. Basic familiarity with the Matlab environment and coding/programming is assumed. The courses will present a mix of both documented and undocumented aspects, which is not available anywhere else. The curriculum is listed below.<br />
This is a unique opportunity to enhance your Matlab coding skills and improve your program&#8217;s usability in a couple of days<!-- , at a very affordable cost -->.<br />
If you are interested in either or both of these seminars, please <a href="mailto:%20altmany%20@gmail.com?subject=Matlab%20training%20Zurich&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab training Zurich&amp;body=Hi Yair, '); return false;">Email me</a> (altmany at gmail dot com).<br />
I can also schedule a dedicated visit to your location, for onsite Matlab training customized to your organization&#8217;s specific needs. Additional information can be found on my <a target="_blank" href="/training/">Training page</a>.<br />
Around the time of the training, I will be traveling to various locations around Switzerland. <!-- in Geneva (Aug 22-27), Bern (Aug 27-28), Zürich (Aug 28-30), and Basel (Aug 30 - Sep 3) --> If you wish to meet me in person to discuss how I could bring value to your project, then please email me (altmany at gmail):</p>
<ul>
<li>Geneva: Aug 22 &#8211; 27</li>
<li>Bern: Aug 27 &#8211; 28</li>
<li>Zürich: Aug 28 &#8211; 30</li>
<li>Stuttgart: Aug 30 &#8211; 31</li>
<li>Basel: Sep 1 &#8211; 3</li>
</ul>
<p><img decoding="async" src="https://undocumentedmatlab.com/images/email-icon.png" width="32" height="22" alt="" style="vertical-align:middle;border:0"/>&nbsp;<a href="mailto: altmany @gmail.com?subject=Matlab consulting/training&#038;body=Hi Yair, &#038;cc=;&#038;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab consulting/training&#038;body=Hi Yair, '); return false;">Email me</a><br />
<span id="more-6992"></span></p>
<hr/>
<h3 id="GUI">Interactive Matlab GUI &#8211; 29 August, 2017</h3>
<ol>
<li>Introduction to Matlab Graphical User Interfaces (GUI)
<ul>
<li>Design principles and best practices</li>
<li>Matlab GUI alternatives</li>
<li>Typical evolution of Matlab GUI developers</li>
</ul>
</li>
<li>GUIDE – MATLAB&#8217;s GUI Design Editor
<ul>
<li>Using GUIDE to design a custom GUI</li>
<li>Available built-in MATLAB uicontrols</li>
<li>Customizing uicontrols</li>
<li>Important figure and uicontrol properties</li>
<li>GUIDE utility windows</li>
<li>The GUIDE-generated file-duo</li>
</ul>
</li>
<li>Customizing GUI appearance and behavior
<ul>
<li>Programmatic GUI creation and control</li>
<li>GUIDE vs. m-programming</li>
<li>Attaching callback functionality to GUI components</li>
<li>Sharing data between GUI components</li>
<li>The handles data struct</li>
<li>Using handle visibility</li>
<li>Position, size and units</li>
<li>Formatting GUI using HTML</li>
</ul>
</li>
<li>Uitable
<ul>
<li>Displaying data in a MATLAB GUI uitable</li>
<li>Controlling column data type</li>
<li>Customizing uitable appearance</li>
<li>Reading uitable data</li>
<li>Uitable callbacks</li>
<li>Additional customizations using Java</li>
</ul>
</li>
<li>Matlab&#8217;s new App Designer and web-based GUI
<ul>
<li>App Designer environment, widgets and code</li>
<li>The web-based future of Matlab GUI and assumed roadmap</li>
<li>App Designer vs. GUIDE – pros and cons comparison</li>
</ul>
</li>
<li>Performance and interactivity considerations
<ul>
<li>Speeding up the initial GUI generation</li>
<li>Improving GUI responsiveness</li>
<li>Actual vs. perceived performance</li>
<li>Continuous interface feedback</li>
<li>Avoiding common performance pitfalls</li>
<li>Tradeoff considerations</li>
</ul>
</li>
</ol>
<p><!-- Throughout the day, a sample data-structure container class will be developed and presented in phases, illustrating the points discussed in the presentation, along with suggestions and discussion on design alternatives, programming quality, efficiency, robustness, maintainability, and performance. In other words, the seminar will include not just a formal presentation of the material but also a live annotated development of a real-world Matlab class that illustrates the presented topics. --><br />
At the end of this seminar, you will have learned how to:</p>
<ul>
<li>apply GUI design principles in Matlab</li>
<li>create simple Matlab GUIs</li>
<li>manipulate and customize graphs, images and GUI components</li>
<li>display Matlab data in a variety of GUI manners, including data tables</li>
<li>decide between using GUIDE, App Designer and/or programmatic GUI</li>
<li>understand tradeoffs in design and run-time performance</li>
<li>comprehend performance implications, to improve GUI speed and responsiveness</li>
</ul>
<hr/>
<h3 id="AMG">Advanced Matlab GUI &#8211; 30 August, 2017</h3>
<ol>
<li>Advanced topics in Matlab GUI
<ul>
<li>GUI callback interrupts and re-entrancy</li>
<li>GUI units and resizing</li>
<li>Advanced HTML formatting</li>
<li>Using hidden (undocumented) properties</li>
<li>Listening to action and property-change events</li>
<li>Uitab, uitree, uiundo and other uitools</li>
</ul>
</li>
<li>Customizing the figure window
<ul>
<li>Creating and customizing the figure&#8217;s main menu</li>
<li>Creating and using context menus</li>
<li>Creating and customizing figure toolbars</li>
</ul>
</li>
<li>Using Java with Matlab GUI
<ul>
<li>Matlab and Java Swing</li>
<li>Integrating Java controls in Matlab GUI</li>
<li>Handling Java events as Matlab callbacks</li>
<li>Integrating built-in Matlab controls/widgets</li>
<li>Integrating JIDE&#8217;s advanced features and professional controls</li>
<li>Integrating 3rd-party Java components: charts/graphs/widgets/reports</li>
</ul>
</li>
<li>Advanced Matlab-Java GUI
<ul>
<li>Customizing standard Matlab uicontrols</li>
<li>Figure-level customization (maximize/minimize, disable etc.)</li>
<li>Containers and position – Matlab vs. Java</li>
<li>Compatibility aspects and trade-offs</li>
<li>Safe programming with Java in Matlab</li>
<li>Java&#8217;s EDT and timing considerations</li>
<li>Deployment (compiler) aspects</li>
</ul>
</li>
</ol>
<p>At the end of this seminar, you will have learned how to:</p>
<ul>
<li>customize the figure toolbar and main menu</li>
<li>use HTML to format GUI appearance</li>
<li>integrate Java controls in Matlab GUI</li>
<li>customize your Matlab GUI to a degree that you never knew was possible</li>
<li>create a modern-looking professional GUI in Matlab</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Font selection components</title>
		<link>https://undocumentedmatlab.com/articles/font-selection-components?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=font-selection-components</link>
					<comments>https://undocumentedmatlab.com/articles/font-selection-components#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 07 Oct 2015 17:45:06 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6013</guid>

					<description><![CDATA[<p>Several built-in components enable programmatic font selection in Matlab GUI - this article explains how. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/font-selection-components">Font selection components</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-type-selection-components" rel="bookmark" title="Plot-type selection components">Plot-type selection components </a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-7-selection-controls" rel="bookmark" title="Matlab toolstrip – part 7 (selection controls)">Matlab toolstrip – part 7 (selection controls) </a> <small>Matlab toolstrips can contain a wide variety of selection controls: popups, combo-boxes, and galleries. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve written here in the past about how Matlab includes multiple alternatives for <a target="_blank" href="/articles/color-selection-components">color selection</a>, <a target="_blank" href="/articles/plot-type-selection-components">plot-type selection</a> and <a target="_blank" href="/articles/date-selection-components">date selection</a> components, that can easily be integrated in Matlab figures (GUI). Today, I will show that Matlab also contains various built-in components for font selection.<br />
These components are used by Matlab itself, integrated within the Preferences panel, print setup popup, property inspector window and so on. In most cases the components have remained unchanged for multiple releases, some existing in Matlab releases for the past decade or more. However, since internal components can change without prior notice, there is no assurance that any particular component will continue to be available in future Matlab releases.<br />
Readers who are interested in additional details about the components mentioned in today&#8217;s post are referred to sections 3.3.3 and 5.5.2 of my book, <i><a target="_blank" href="/books/matlab-java">Undocumented Secrets of MATLAB-Java Programming</a></i>.</p>
<h3 id="uisetfont">uisetfont</h3>
<p>The only documented font-selection alternative in Matlab is <i><b>uisetfont</b></i>, which presents a popup dialog window that returns the selected font properties in a simple Matlab struct:</p>
<pre lang='matlab'>
>> font = uisetfont
font =
      FontName: 'Arial'
    FontWeight: 'normal'
     FontAngle: 'normal'
     FontUnits: 'points'
      FontSize: 10
</pre>
<p><center><figure style="width: 367px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's uisetfont dialog" src="https://undocumentedmatlab.com/images/uisetfont.png" title="Matlab's uisetfont dialog" width="367" height="363" /><figcaption class="wp-caption-text">Matlab's <i><b>uisetfont</b></i> dialog</figcaption></figure></center><br />
<span id="more-6013"></span><br />
The main drawback of <i><b>uisetfont</b></i> is the fact that it displays a separate non-resizable modal dialog window. We cannot embed <i><b>uisetfont</b></i> within our own panel, integrated in our GUI figure.</p>
<h3 id="DesktopFontPicker">DesktopFontPicker</h3>
<p><code>DesktopFontPicker</code> is a Swing component that presents a font selection panel that can easily be inserted into any Matlab GUI container (figure, panel or tab) using <a target="_blank" href="/articles/javacomponent">the <i><b>javacomponent</b></i> function</a>:</p>
<pre lang='matlab'>
font = java.awt.Font('Tahoma',java.awt.Font.PLAIN, 11);
jFontPanel = com.mathworks.widgets.DesktopFontPicker(true, font);
[jhPanel,hContainer] = javacomponent(jFontPanel, [10,10,250,170], gcf);
</pre>
<p><center><figure style="width: 250px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="DesktopFontPicker panel" src="https://undocumentedmatlab.com/images/DesktopFontPicker.gif" title="DesktopFontPicker panel" width="250" height="170" /><figcaption class="wp-caption-text"><code>DesktopFontPicker</code> panel</figcaption></figure></center><br />
Instead of the “Use desktop font” label, we can use our own label:</p>
<pre lang='matlab'>jFontPanel.setUseDesktopFontLabel('Use Yair''s standard font...')</pre>
<p><center><figure style="width: 347px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Non-standard DesktopFontPicker panel" src="https://undocumentedmatlab.com/images/DesktopFontPicker2.png" title="Non-standard DesktopFontPicker panel" width="347" height="290" /><figcaption class="wp-caption-text">Non-standard <code>DesktopFontPicker</code> panel</figcaption></figure></center><br />
To extract the selected font, use one of the following methods provided by <code>DesktopFontPicker</code>:</p>
<pre lang='matlab'>
jFont = jFontPanel.getSelectedFont();  % returns a java.awt.Font object
flag = jFontPanel.getUseDesktopFont();  % true if top radio-button is selected; false if custom font is selected
</pre>
<h3 id="FontPrefsPanel">FontPrefsPanel</h3>
<p>The builtin <code>com.mathworks.mlwidgets.prefs.FontPrefsPanel</code> class is used in Matlab to display the font preferences panel in the Preferences window. We can integrate it directly in our GUI:</p>
<pre lang='matlab'>
jFontPanel=com.mathworks.mlwidgets.prefs.FontPrefsPanel(java.awt.Dimension);
[jhPanel,hContainer] = javacomponent(jFontPanel, [1,1,500,470], gcf);
</pre>
<p>Using this class is admittedly more cumbersome than <code>DesktopFontPicker</code> and I would not recommend using it in practice.</p>
<h3 id="FontPicker">FontPicker</h3>
<p>Font selection can also be shown with drop-downs (combo-boxes), rather than with lists as in <code>DesktopFontPicker</code>, <code>FontPrefsPanel</code>, or <i><b>uisetfont</b></i>. Use of drop-downs significantly reduces the display &#8220;real-estate&#8221; required by the control. This is useful in forms where the font selection is only one of several user-configurable options, and where enough space must be reserved for other configuration controls. We can do this using the <code>com.mathworks.widgets.fonts.FontPicker</code> class.<br />
Up until Matlab release R2010a, <code>FontPicker</code>&#8216;s constructor accepted optional parameters of a pre-selected font (a <code>java.awt.Font</code> object), an optional boolean flag indicating whether to display sample text using the selected font, an optional layout indicator, and optional list of selectable font names. Several screenshots of different parameter combinations are shown below:</p>
<pre lang='matlab'>
import com.mathworks.widgets.fonts.FontPicker
jFontPicker = FontPicker(font, sampleFlag, layout);
[hjFontPicker, hContainer] = javacomponent(jFontPicker, position, gcf);
</pre>
<table style="background: white; border: none;">
<tbody style="text-align: center;">
<tr>
<td style="border: none;"> </td>
<td style="border: none;"><img loading="lazy" decoding="async" alt="FontPicker" src="https://undocumentedmatlab.com/images/FontPicker1.png" title="FontPicker" width="140" height="40" /></td>
<td style="border: none;"><img loading="lazy" decoding="async" alt="FontPicker" src="https://undocumentedmatlab.com/images/FontPicker2.png" title="FontPicker" width="225" height="20" /></td>
<td style="border: none;"><img loading="lazy" decoding="async" alt="FontPicker" src="https://undocumentedmatlab.com/images/FontPicker3.png" title="FontPicker" width="225" height="80" /></td>
</tr>
<tr>
<td>font=</td>
<td>[]</td>
<td><code>java.awt.Font('Tahoma', java.awt.Font.PLAIN, 8 )</code></td>
<td>[]</td>
</tr>
<tr>
<td>sampleFlag=</td>
<td><code>false</code></td>
<td><code>false</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td>layout=</td>
<td><code>FontPicker.GRID_LAYOUT</code> (=1)</td>
<td><code>FontPicker.LONG_LAYOUT</code> (=2)</td>
<td><code>FontPicker.LONG_LAYOUT</code> (=2)</td>
</tr>
<tr>
<td>position=</td>
<td>[10,200,140,40]</td>
<td>[10,200,225,20]</td>
<td>[10,200,225,80]</td>
</tr>
</tbody>
</table>
<p>As before, the selected font can be retrieved using <code>jFontPicker.getSelectedFont()</code>.<br />
In Matlab release R2010b, <code>FontPicker</code>&#8216;s interface changed, and the above code no longer works. This highlights a common pitfall in future-compatibility of internal components: even when the components remain, their interface sometimes changes. Here is the new code format, starting with R2010b:</p>
<pre lang='matlab'>
jLayout = javaMethod('valueOf', 'com.mathworks.widgets.fonts.FontPicker$Layout', 'WIDE_WITH_SAMPLE');  % options: COMPACT, WIDE, WIDE_WITH_SAMPLE
jFont = java.awt.Font('Tahoma', java.awt.Font.PLAIN, 10);  % initial font to display (may not be [])
jFontPicker = com.mathworks.widgets.fonts.FontPicker(jFont, jLayout);
jFontPanel = jFontPicker.getComponent;
[jhPanel,hContainer] = javacomponent(jFontPanel, [10,10,250,120], gcf);
</pre>
<h3 id="FontChooserPanel">FontChooserPanel</h3>
<p>As a final alternative for font selection, we can use the JIDE font-selection component. This component has two variants: as a drop-down/combo-box (<code>com.jidesoft.combobox.FontComboBox</code>) and as a standard <code>JPanel</code> (<code>com.jidesoft.combobox.FontChooserPanel</code>):</p>
<pre lang='matlab'>
jFont = java.awt.Font('arial black',java.awt.Font.PLAIN, 8);
jFontPicker = com.jidesoft.combobox.FontComboBox(jFont);
[hjFontPicker, hContainer] = javacomponent(jFontPicker, position, gcf);
set(hjFontPicker, 'ItemStateChangedCallback', @myCallbackFunction);
</pre>
<p><center><figure style="width: 264px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="JIDE's FontComboBox" src="https://undocumentedmatlab.com/images/JIDE_FontComboBox.png" title="JIDE's FontComboBox" width="264" height="254" /><figcaption class="wp-caption-text">JIDE's FontComboBox</figcaption></figure></center><br />
Within the callback function, use <i>getSelectedFont()</i> to retrieve the updated font (again, a <code>java.awt.Font</code> object). There is also a corresponding <i>setSelectedFont(font)</i> to programmatically update the control with the specified <code>Font</code> object.<br />
The combo-box presents a <code>FontChooserPanel</code>, which can be accessed (via the <b>PopupPanel</b> property or the corresponding <i>getPopupPanel()</i> method) after it has been initially created. Thereafter, the panel can be customized. For example, the preview text can be modified via the panel&#8217;s <b>PreviewText</b> property (or the <i>setPreviewText(text)</i> method).<br />
The same <code>FontChooserPanel</code> can also be displayed as a stand-alone font-selection panel, unrelated to any combo-box. Different GUI requirements might prefer using a compact combo-box approach, or the larger stand-alone panel.<br />
This combo-box/panel duality is a common feature of JIDE controls. I have previously shown it in my <a target="_blank" href="/articles/color-selection-components">color selection components</a> and <a target="_blank" href="/articles/date-selection-components">date selection components</a> articles.</p>
<h3 id="uicontrol">popupmenu uicontrol</h3>
<p>As another example of using a font-selection drop-down (combo-box), we can use a standard Matlab popupmenu <i><b>uicontrol</b></i>, setting its <b>String</b> property value to a cell-array containing the supported system&#8217;s fonts (as returned by the <i><b>listfonts</b></i> function). A nice twist here is to use the undocumented trick that all <a target="_blank" href="/articles/html-support-in-matlab-uicomponents">Matlab uicontrols inherently support HTML</a> to list each of the fonts in their respective font style:</p>
<pre lang='matlab'>
fontStr = @(font) ['<html><font face="' font '">' font '</font></html>'];
htmlStr = cellfun(fontStr, listfonts, 'uniform',false);
uicontrol('style','popupmenu', 'string',htmlStr, 'pos',[20,350,100,20]);
</pre>
<p><center><figure style="width: 355px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="HTML-rendered fonts popup menu" src="https://undocumentedmatlab.com/images/html_fonts.png" title="HTML-rendered fonts popup menu" width="355" height="460" /><figcaption class="wp-caption-text">HTML-rendered fonts popup menu</figcaption></figure></center><br />
Note that we could also use a listbox <i><b>uicontrol</b></i> using the same code.</p>
<h3 id="Austria">Austria visit, 11-15 October, 2015</h3>
<p>I will be travelling to clients in Austria next week, between October 11-15. If you are in Austria and wish to meet me to discuss how I could bring value to your work, then please email me (altmany at gmail).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/font-selection-components">Font selection components</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-type-selection-components" rel="bookmark" title="Plot-type selection components">Plot-type selection components </a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-7-selection-controls" rel="bookmark" title="Matlab toolstrip – part 7 (selection controls)">Matlab toolstrip – part 7 (selection controls) </a> <small>Matlab toolstrips can contain a wide variety of selection controls: popups, combo-boxes, and galleries. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/font-selection-components/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Sliders in Matlab GUI</title>
		<link>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sliders-in-matlab-gui</link>
					<comments>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 Jun 2015 18:00:58 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5827</guid>

					<description><![CDATA[<p>Professional-looking slider controls can easily be integrated in Matlab GUI. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui">Sliders in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui-part-2" rel="bookmark" title="Sliders in Matlab GUI &#8211; part 2">Sliders in Matlab GUI &#8211; part 2 </a> <small>Matlab contains a variety of ways to define/display slider controls in GUI windows. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>One of my consulting clients asked me last week if I knew an easy way to integrate a range (dual-knob) slider control in Matlab GUI. Today&#8217;s post is an expansion of the answer I provided him, which I though might interest other Matlab users.</p>
<ul>
<li><a href="/articles/sliders-in-matlab-gui#Matlab">Matlab vs. Java sliders</a></li>
<li><a href="/articles/sliders-in-matlab-gui#JSlider">Using JSlider</a></li>
<li><a href="/articles/sliders-in-matlab-gui#range">Range (dual-knob) sliders</a></li>
<li><a href="/articles/sliders-in-matlab-gui#AppDesigner">AppDesigner &#8211; Matlab&#8217;s new GUI</a></li>
<li><a href="/articles/sliders-in-matlab-gui#conclusions">Conclusions and some personal musings</a></li>
</ul>
<h3 id="Matlab">Matlab vs. Java sliders</h3>
<p>As funny as it may sound, Matlab&#8217;s so-called &#8220;slider&#8221; control (<code>uicontrol('Style','slider')</code>) is actually implemented as a scroll-bar, rather than the more natural <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html">JSlider</a>. I believe that this is due to a design decision that occurred sometime in the 1990&#8217;s (sliders were not as prevalent then as they are nowadays). This was never corrected, probably for backward-compatibility reasons. So to this day, Matlab&#8217;s so-called &#8220;slider&#8221; is actually a scroll-bar, and we do not [yet] have a real slider control in standard Matlab, apparently since the &#8216;slider&#8217; <i><b>uicontrol</b></i> style is already in use. Spoiler alert: this <i>will</i> change soon &#8212; keep reading.<br />
It gets worse: for some reason Matlab&#8217;s implementation of the so-called &#8220;slider&#8221; uses a Windows95 look-and-feel that makes the control look antique in today&#8217;s GUI standards. Using Java Swing&#8217;s standard <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JScrollBar.html">JScrollBar</a> control would at least have made it appear more consistent with the other Matlab controls, which are all based more closely on Java Swing:<br />
<figure style="width: 210px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt='Matlab "slider" uicontrol (bottom), Java JScrollBar (above), and JSlider (top 2)' src="https://undocumentedmatlab.com/images/slider_vs_scrollbars.gif" title='Matlab "slider" uicontrol (bottom), Java JScrollBar (above), and JSlider (top 2)' width="210" height="145" /><figcaption class="wp-caption-text">Matlab "slider" <i><b>uicontrol</b></i> (bottom), <br />Java <code>JScrollBar</code> (above), <br />and <code>JSlider</code> (top 2)</figcaption></figure></p>
<pre lang='matlab'>
% Standard Matlab "slider"
uicontrol('style','slider', 'position',[10,10,200,20]);
% Standard Java JScrollBar
jScrollbar = javax.swing.JScrollBar;
jScrollbar.setOrientation(jScrollbar.HORIZONTAL);
javacomponent(jScrollbar,[10,40,200,20]);
% Standard Java JSlider (20px high if no ticks/labels, otherwise use 45px)
jSlider = javax.swing.JSlider;
javacomponent(jSlider,[10,70,200,45]);
</pre>
<p>I advise users of the current Matlab GUI to use <code>JScrollBar</code> or <code>JSlider</code>, rather than Matlab&#8217;s standard &#8220;slider&#8221; <i><b>uicontrol</b></i>. The rest of today&#8217;s post will discuss the <code>JSlider</code> variant.<br />
<span id="more-5827"></span></p>
<h3 id="JSlider">Using JSlider</h3>
<p>As shown above, we can use the <i><b><a target="_blank" href="/articles/javacomponent">javacomponent</a></b></i> function to display any Java component in a Matlab container (such as <i><b>uipanel</b></i> or figure). We can easily modify the slider&#8217;s appearance using its internal properties:</p>
<pre lang='matlab'>set(jSlider, 'Value',84, 'MajorTickSpacing',20, 'PaintLabels',true);  % with labels, no ticks</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x016.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>set(jSlider, 'Value',22, 'PaintLabels',false, 'PaintTicks',true);  % with ticks, no labels</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x017.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>jSlider.setPaintLabels(true);  % or: jSlider.setPaintLabels(1);  % with both ticks and labels</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x018.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>
[jhSlider, hContainer] = javacomponent(jSlider,[10,10,100,40]);
set(jSlider, 'Value',72, 'Orientation',jSlider.VERTICAL, 'MinorTickSpacing',5);
set(hContainer,'position',[10,10,40,100]); %note container size change
</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x019.png" title="JSlider customization" alt="JSlider customization" width="70" height="120" /></center><br />
We can query the current slider value via its <b>Value</b> property:</p>
<pre lang='matlab'>
>> value = get(jSlider,'Value');  % or: value = jSlider.getValue;
value =
    29
</pre>
<p>We can easily attach Matlab callback functions to slider value-change events:</p>
<pre lang='matlab'>
>> hjSlider = handle(jSlider, 'CallbackProperties')
hjSlider =
	javahandle_withcallbacks.javax.swing.JSlider
>> hjSlider.StateChangedCallback = @(hjSlider,eventData) disp(get(hjSlider,'Value'));
>> set(hjSlider, 'StateChangedCallback', @myCallback);  %alternative
</pre>
<p>As you can see, standard Java controls (such as <code>JSlider</code> here) are very simple to customize and use in Matlab GUI. I have shown more complex customizations <a target="_blank" href="/articles/javacomponent#comment-80247">elsewhere in this blog</a>, as well as in my <a target="_blank" href="/books/matlab-java">Matlab-Java programming book</a>.<br />
Note that <code>JSlider</code> (and Java sliders in general) only supports integer values, so if you need floating-point values you&#8217;d either need to find some other Java Swing component somewhere that supports what you need, or do the scaling yourself with some text label. I recently created a Matlab class wrapper for a client that does exactly that: the underlying component was a  Java slider and the labels were updated to display floating-point values, dynamically updated based on the Matlab class object&#8217;s properties. It only took a short morning to create a fully-functional generic slider class that works quite well.</p>
<h3 id="range">Range (dual-knob) sliders</h3>
<p>This brings me to my client&#8217;s query that I mentioned at the beginning of this post: <code>JSlider</code> only contains a single knob. Is it possible to integrate a range (dual-knob) slider?<br />
My initial response was to simply google for &#8220;<a target="_blank" rel="nofollow" href="https://www.google.co.il/search?q=java%20range%20slider">Java range slider</a>&#8220;. This returns numerous different controls, both open-source and commercial, that we can download and integrate in Matlab. All it takes is to download the <i>*.class, *.zip</i> or <i>*.jar</i> file that contains the component, add it to Matlab Java classpath using the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/javaaddpath.html">javaaddpath</a></b></i> function, and then use the <i><b>javacomponent</b></i> to display it, just as we did with <code>JSlider</code> above.<br />
This is simple enough, but then I thought of an even simpler solution, namely to use JIDE&#8217;s library of commercial-grade controls that is pre-bundled in Matlab. Surely enough, a quick search in <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/overview-summary.html">JIDE&#8217;s enormous catalog</a> yielded its <code><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/RangeSlider.html">RangeSlider</a></code> component, which extends <code>JSlider</code> with a dual knob. <code>RangeSlider</code>&#8216;s appearance has changed somewhat across Matlab releases (or actually, JIDE releases, as they are integrated within the corresponding Matlab releases), but its basic functionality remained unchanged:</p>
<pre lang='matlab'>
jRangeSlider = com.jidesoft.swing.RangeSlider(0,100,20,70);  % min,max,low,high
jRangeSlider = javacomponent(jRangeSlider, [0,0,200,80], gcf);
set(jRangeSlider, 'MajorTickSpacing',25, 'MinorTickSpacing',5, 'PaintTicks',true, 'PaintLabels',true, ...
    'Background',java.awt.Color.white, 'StateChangedCallback',@myCallbackFunc);
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="RangeSlider in R2010b" src="https://undocumentedmatlab.com/images/RangeSlider_R2010b.gif" title="RangeSlider in R2010b" width="200" height="50" /> &nbsp; <img loading="lazy" decoding="async" alt="RangeSlider in R2014b" src="https://undocumentedmatlab.com/images/RangeSlider_R2014b.gif" title="RangeSlider in R2014b" width="200" height="50" /><figcaption class="wp-caption-text"><code>RangeSlider</code> in R2010b (left), R2014b (right)</figcaption></figure></center><br />
We can move the two knobs relative to each other. We can also move the entire range (i.e., both knobs at once), by either dragging the square on top of the right knob (R2010b), or by dragging the space between the two knobs (R2014b).<br />
The benefit of JIDE controls is that they are pre-bundled in every Matlab installation and deployed MCR. There is no need to download anything, nor to use <i><b>javaaddpath</b></i>. All the richness of JIDE&#8217;s commercial-grade libraries (at least those libraries used in Matlab, which is plenty) is automatically available to us within Matlab, just as easily as the standard Java Swing controls. MathWorks has already paid a small fortune to integrate JIDE&#8217;s libraries in Matlab, and we can use it free of charge within Matlab GUIs. This is a great (and sadly undocumented) advantage of Matlab GUI. Matlab GUI programmers who wish to enrich their GUI are strongly encourages to take the time to review the long list of controls provide by JIDE in Matlab. I&#8217;ve posted <a target="_blank" href="/articles/tag/jide">quite a few articles</a> on using JIDE components in Matlab &#8211; feel free to take a look and see the richness that JIDE can bring to your GUI. Additional material can be found in my Matlab-Java programming book.<br />
In the specific case of <code>RangeSlider</code>, this control is part of the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/oss.htm">JIDE Common Layer</a> that JideSoft open-sourced a few years ago. This means that we can <a target="_blank" rel="nofollow" href="https://github.com/jidesoft/jide-oss">download</a> the latest version of this library and use it in Matlab, in case it has some new component that is still not available in our version of Matlab. For example, Matlab R2014b includes JIDE version 3.4.1, released by JideSoft on May 2012 &#8211; the latest version (3.6.9, released last week) includes numerous fixes and improvements that were integrated in the past 3 years:</p>
<pre lang='matlab'>
>> com.jidesoft.utils.Lm.getProductVersion
ans =
3.4.1
</pre>
<p>Note that JIDE&#8217;s online documentation (<a target="_blank" rel="nofollow" href="https://www.jidesoft.com/products/JIDE_Common_Layer_Developer_Guide.pdf">PDF</a>, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/overview-summary.html">javadoc</a>, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/oss.htm">webpage</a>) always refers to the latest version. To use the latest Common-layer library in Matlab, simply <a target="_blank" rel="nofollow" href="https://github.com/jidesoft/jide-oss">download it</a> and replace Matlab&#8217;s pre-bundled <i>&lt;matlabroot&gt;/java/jarext/jide/jide-common.jar</i> file. Be careful with changing Matlab&#8217;s installation files (such as this one), as there is always a risk that some Matlab functionality might break. So always keep a copy of the original file, in case you need to revert your changes. Alternatively, place the <i>jide-common.jar</i> file in some other user folder and use it in Matlab on an as-needed basis using <i><b>javaaddpath</b></i> and <i><b>javarmpath</b></i>.<br />
Using the latest commercial (non-open-sourced) JIDE libraries, such as <i>jide-grids.jar</i>, <i>jide-components.jar</i> or <i>jide-charts.jar</i>, is only possible if you purchase them from JideSoft. But as noted, we can freely use the older bundled libraries in our Matlab GUIs without paying JideSoft anything.<br />
<b><u>Disclaimer</u></b>: I am an engineer, not a lawyer. What I said above is my personal opinion; it is not legal advice. If you are unsure about licensing of JIDE components in your programs, contact MathWorks or JideSoft.</p>
<h3 id="AppDesigner">AppDesigner &#8211; Matlab&#8217;s new GUI</h3>
<p>Last autumn, with little fanfare, MathWorks released the App Designer toolbox, which can be freely <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/48142-app-designer">downloaded from the File Exchange</a>. This is not just another File Exchange utility. It is in fact an official MathWorks <a target="_blank" rel="nofollow" href="http://www.mathworks.com/products/matlab/app-designer/tech-preview.html">Technical Preview</a> that is both functional by itself, and also provides very interesting insight of Matlab&#8217;s upcoming new GUI. MathWorks have not announced exactly when this new AppDesigner will replace the aging GUIDE in Matlab. But the fact that AppDesigner is an actual working product in the public domain since late 2014, and that MathWorks has officially endorsed it as a &#8220;Technical Preview&#8221;, mean that this day is close.<br />
In the new AppDesigner, sliders finally appear modern, complete with all sorts of customizable properties:<br />
<center><figure style="width: 598px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Sliders in Matlab's new AppDesigner" src="https://undocumentedmatlab.com/images/slider_AppDesigner.png" title="Sliders in Matlab's new AppDesigner" width="598" height="376" /><figcaption class="wp-caption-text">Sliders in Matlab's new AppDesigner</figcaption></figure></center><br />
Java controls still provide more customizability than Matlab, even in the new AppDesigner, but the functionality gap is now significantly reduced. This provides the flexibility of modern easy-to-create/maintain GUIs for users who do not need to preserve backward-compatibility with existing GUIs or extra customizabilty enabled by Java, while preserving the functionality for those who do.<br />
Java components and even standard Matlab <i><b>uicontrol</b></i>s cannot be added to an AppDesigner window because it is not a standard Java <code>JFrame</code> window. The new App window has its own set of controls, separate from <i><b>uicontrols</b></i> (topic for a separate blog post someday). However, we can always keep using <i><b>javacomponent</b></i> and <i><b>uicontrol</b></i> in plain-ol&#8217; figures, as before, side-by-side with the new AppDesigned windows. The new App window can be created using the new <i><b>appwindow</b></i> function, whereas the existing <i><b>figure</b></i> function creates a standard figure window (basically a Java <code>JFrame</code>) that accepts <i><b>javacomponent</b></i> and <i><b>uicontrol</b></i>. Maybe one day I&#8217;ll find out if there&#8217;s a way to combine these two seemingly disparate sets of GUIs. In the meantime I&#8217;m content that there&#8217;s a new way to create Matlab GUIs that has not previously existed.<br />
AppDesigner is a very nice addition for Matlab GUI builders, and it will get even better with time. Having looked at some of the internals, I&#8217;m drooling over the potential improvements. MathWorks has invested quite a bit in this new product, so I&#8217;m confident that many of these improvements will find their way into AppDesigner in the upcoming releases. I just hope it will remain a free utility and will not turn into an addon toolbox when officially released (I have not seen any mention about this either way, so it&#8217;s still an open question; I&#8217;ll clarify this point here when I learn something). For the time being, AppDesigner is free to use.<br />
MathWorks is actively looking for ways to improve AppDesigner, so if you find any functionality that is missing or buggy, please provide feedback:<br />
<center><figure style="width: 280px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Feedback for Matlab's new AppDesigner" src="http://www.mathworks.com/images/nextgen/supporting/products/matlab-app-designer/feedback.png" title="Feedback for Matlab's new AppDesigner" width="280" height="143" /><figcaption class="wp-caption-text">Feedback for Matlab's new AppDesigner</figcaption></figure></center></p>
<h3 id="conclusions">Conclusions and some personal musings</h3>
<p>Matlab itself has kept its Desktop GUI relatively modern, and integrates advanced JIDE GUI controls internally. But until AppDesigner came about, Matlab application builders were not provided with similarly modern documented GUI components and design tools, in keeping with the times.<br />
It is indeed possible, as I&#8217;ve <a target="_blank" href="/articles/auto-completion-widget">repeatedly claimed</a> in this blog, to create professional-looking GUIs in Matlab. However, this currently requires using undocumented features and Java controls.<br />
In Matlab&#8217;s upcoming AppDesigner, making professional-looking Matlab GUIs will be easier, with sleek new controls, user-friendly visual layout, and easy-to-maintain class-based code. I still find the tech-preview to be lacking in some respects, and not integrated with the existing GUI functionality. Still, the fact that MathWorks has gone out of its way to provide a Technical Preview of its upcoming new GUI, despite its normal reluctance to provide a technical development roadmap, shows a commitment to improving Matlab&#8217;s user-facing front-end. This makes me optimistic that most shortcomings will be solved by the time AppDesigner is officially released, hopefully soon.<br />
Until this happens, and possibly even later, we can significantly improve Matlab&#8217;s standard GUI using Java in standard figure windows. Interested readers can find out more information about integrating Java controls in Matlab GUI in my book &#8220;<i><b><a target="_blank" href="/books/matlab-java">Undocumented Secrets of MATLAB-Java Programming</a></b></i>&#8221; (CRC Press, 2011, ISBN 978-1439869031). If you already have this book, please be kind enough to post your feedback on it on Amazon (<a target="_blank" rel="nofollow" href="http://www.amazon.com/Undocumented-Secrets-MATLAB-Java-Programming-Altman/product-reviews/1439869030?sortBy=bySubmissionDateDescending#productSummary">link</a>), for the benefit of others.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui">Sliders in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui-part-2" rel="bookmark" title="Sliders in Matlab GUI &#8211; part 2">Sliders in Matlab GUI &#8211; part 2 </a> <small>Matlab contains a variety of ways to define/display slider controls in GUI windows. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui/feed</wfw:commentRss>
			<slash:comments>59</slash:comments>
		
		
			</item>
		<item>
		<title>Using JIDE combo-boxes</title>
		<link>https://undocumentedmatlab.com/articles/using-jide-combo-boxes?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-jide-combo-boxes</link>
					<comments>https://undocumentedmatlab.com/articles/using-jide-combo-boxes#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 16 Oct 2013 13:10:42 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[JIDE]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4261</guid>

					<description><![CDATA[<p>Matlab includes many custom JIDE combo-box controls that can be used in Matlab GUIs out of the box. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/using-jide-combo-boxes">Using JIDE combo-boxes</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editable-combo-box" rel="bookmark" title="Editable combo-box">Editable combo-box </a> <small>Matlab's popup menu (combo-box) control is quite limited in its abilities. This article explains how we can work around these limitations. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Continuing last week&#8217;s article on customized combo-boxes (a.k.a. <i>popup menus</i> or <i>drop-downs</i>), today I discuss how we can use <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/">JIDE</a>&#8216;s vast array of custom professional combo-boxes in our Matlab GUI.<br />
As I&#8217;ve already noted here in <a target="_blank" href="/articles/tag/jide/">several</a> articles, Matlab heavily uses JIDE&#8217;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&#8217;ve recently shown an example of this in my <a target="_blank" href="/articles/treetable/"><i><b>treeTable</b></i></a> utility, which greatly extends Matlab&#8217;s standard <i><b>uitable</b></i>. After using <i><b>treeTable</b></i> for a while, it&#8217;s difficult to go back to using the plain standard <i><b>uitable</b></i>&#8230; A similar experience will undoubtedly occur after using some of JIDE&#8217;s combo-boxes.<br />
<center><figure style="width: 580px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="DateSpinnerComboBox" src="https://undocumentedmatlab.com/images/JIDE_DateSpinnerComboBox.png" title="DateSpinnerComboBox" width="210" height="174" /> <img loading="lazy" decoding="async" alt="CheckBoxListComboBox" src="https://undocumentedmatlab.com/images/JIDE_CheckBoxListComboBox.png" title="CheckBoxListComboBox" width="174" height="137" /> <img loading="lazy" decoding="async" alt="ColorComboBox" src="https://undocumentedmatlab.com/images/JIDE_ColorComboBox.png" title="ColorComboBox" width="156" height="174" /><figcaption class="wp-caption-text">Some of the JIDE combo-box controls</figcaption></figure></center><br />
<span id="more-4261"></span></p>
<h3 id="JIDE">JIDE combo-boxes</h3>
<p>JIDE&#8217;s combo-box controls are generally grouped in the JIDE Grids package and extend the standard Java Swing <code>JComponent</code> (JIDESoft actually found it easier to extend <code>JComponent</code> than <code>JComboBox</code>, but users really have nothing to complain &#8211; 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 <code>com.jidesoft.combobox</code> Java package, which groups the combo-box components. You can find further details on JIDE Grids in the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf">Developer Guide</a> and the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/">Javadoc documentation</a>.<br />
Back in 2010, I <a target="_blank" href="/articles/date-selection-components/">explained</a> how we can use one of these components, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateComboBox.html"><code>DateComboBox</code></a>, and its close associate <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateSpinnerComboBox.html"><code>DateSpinnerComboBox</code></a>. Today I extend the coverage to briefly examine JIDE&#8217;s other custom combo-box controls.<br />
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 <code>xxxChooserPanel</code> and its corresponding combo-box is called <code>xxxComboBox</code>. So, for example, we would have <code>ColorComboBox</code> coupled with <code>ColorChooserPanel</code>. After the combo-box is created, the panel can be accessed and customized via the combo-box’s <b>PopupPanel</b> property or the corresponding <i>getPopupPanel()</i> method. The panel can also be displayed as a standalone control, as I&#8217;ve shown in the <a target="_blank" rel="nofollow" href="/articles/date-selection-components/"><code>DateComboBox</code> article</a>. GUI designers can choose whether to use a compact combo-box or the full-size panel control.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/ListComboBox.html"><code>ListComboBox</code></a> – a simple combo-box that accepts a list (cell array) of selectable values (e.g., string values). This is the simplest JIDE combo-box. It doesn&#8217;t add much over Matlab&#8217;s standard combo-box control except the ability to easily set the <b>MaximumRowCount</b> property (default value =8). On the other hand, using <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i></a> we can do the same thing with Matlab&#8217;s control&#8230;</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MultilineStringComboBox.html"><code>MultilineStringComboBox</code></a> – a combo box that enables entering a string item that has multiple lines of text. A similar control is <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/StringArrayComboBox.html"><code>StringArrayComboBox</code></a> that simply formats the multi-line string differently in the result, separating the multi-lines with a &#8216;;&#8217; character.</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MultiSelectListComboBox.html"><code>MultiSelectListComboBox</code></a> – a combo-box that enables selecting multiple items using a combination of &lt;Shift&gt;-click and &lt;Ctrl&gt;-click<br />
<center><figure style="width: 174px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MultiSelectListComboBox" src="https://undocumentedmatlab.com/images/JIDE_MultiSelectListComboBox.png" title="MultiSelectListComboBox" width="174" height="137" /><figcaption class="wp-caption-text">MultiSelectListComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/CheckBoxListComboBox.html"><code>CheckBoxListComboBox</code></a> &#8211; a combo-box that presents a multi-selection panel using check-boxes. It will be discussed in next week&#8217;s article.<br />
<center><figure style="width: 174px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="CheckBoxListComboBox" src="https://undocumentedmatlab.com/images/JIDE_CheckBoxListComboBox.png" title="CheckBoxListComboBox" width="174" height="137" /><figcaption class="wp-caption-text">CheckBoxListComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/CalculatorComboBox.html"><code>CalculatorComboBox</code></a> – a combo-box control that displays the result of simple arithmetic calculations. Possible customizations include the ability to set the calculator buttons&#8217; size and gap, the displayed number format, the initial value etc. &#8211; all via the <b>Calculator</b> property that returns a customizable <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/Calculator.html"><code>com.jidesoft.swing.Calculator</code></a> object.<br />
<center><figure style="width: 116px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="CalculatorComboBox" src="https://undocumentedmatlab.com/images/JIDE_CalculatorComboBox.png" title="CalculatorComboBox" width="116" height="162" /><figcaption class="wp-caption-text">CalculatorComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/ColorComboBox.html"><code>ColorComboBox</code></a> – a combo-box control that enables color selection. Matlab includes a large number of color selectors, as explained in <a target="_blank" href="/articles/color-selection-components/">this article</a>. Possible customizations of the <code>ColorComboBox</code> control include the ability to hide the color&#8217;s RGB value (<b>ColorValueVisible</b> property, boolean, default=true), hide the colored icon rectangle (<b>ColorIconVisible</b> property, boolean, default=true), make the control look like an editbox rather than a combo-box (<b>ButtonVisible</b> property, boolean, default=true), allow the &#8220;More colors&#8230;&#8221; features (<b>AllowMoreColors</b>, boolean, default=true) etc.<br />
<center><figure style="width: 156px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="ColorComboBox" src="https://undocumentedmatlab.com/images/JIDE_ColorComboBox.png" title="ColorComboBox" width="156" height="174" /><figcaption class="wp-caption-text">ColorComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/JideColorSplitButton.html"><code>JideColorSplitButton</code></a> – a control very similar to <code>ColorComboBox</code>, meant for usage in toolbars or wherever a narrow color-selection control is needed:<br />
<center><figure style="width: 156px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="JideColorSplitButton" src="https://undocumentedmatlab.com/images/JideColorSplitButton.png" title="JideColorSplitButton" width="156" height="173"/><figcaption class="wp-caption-text">JideColorSplitButton</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateComboBox.html"><code>DateComboBox</code></a> – presents a date-selection combo-box, whose attributes (day/month names, display format etc.) are taken from the system definitions. JIDE&#8217;s date-selection components were discussed in a <a target="_blank" href="/articles/date-selection-components/">dedicated article</a>. Possible customizations include the ability to display an integrated time-selector sub-component (via the <b>TimeDisplayed</b> property: boolean, default=false and <b>TimeFormat</b> string), week numbers (<b>ShowWeekNumbers</b>, boolean, default=true), &lt;OK&gt; button (<b>ShowOKButton</b>, boolean, default=false), the &lt;Today&gt; button (<b>ShowTodayButton</b>, boolean, default=true) and the &lt;None&gt; button (<b>ShowNoneButton</b>, boolean, default=true).<br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="DateComboBox" src="https://undocumentedmatlab.com/images/JIDE_DateComboBox.png" title="DateComboBox" width="200" height="166" /><figcaption class="wp-caption-text">DateComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateSpinnerComboBox.html"><code>DateSpinnerComboBox</code></a> – presents a date-selection combo-box that includes both the <code>DateComboBox</code> and a spinner control<br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="DateSpinnerComboBox" src="https://undocumentedmatlab.com/images/JIDE_DateSpinnerComboBox.png" title="DateSpinnerComboBox" width="200" height="166" /><figcaption class="wp-caption-text">DateSpinnerComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MonthComboBox.html"><code>MonthComboBox</code></a> – a month-selection combo-box, similar to <code>DateComboBox</code> but without the ability to select individual days, only full months<br />
<center><figure style="width: 242px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MonthComboBox" src="https://undocumentedmatlab.com/images/JIDE_MonthComboBox.png" title="MonthComboBox" width="242" height="228" /><figcaption class="wp-caption-text">MonthComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/FileChooserComboBox.html"><code>FileChooserComboBox</code></a> – a combo-box that displays a file-selection window when activated. Customizations include the ability to set the <b>CurrentDirectoryPath</b> used by the popup window.</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/FolderChooserComboBox.html"><code>FolderChooserComboBox</code></a> – a combo-box that displays a folder-selection window when activated</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/FontComboBox.html"><code>FontComboBox</code></a> &#8211; a font selection combobox (Matlab has several other font-selection components that we can use, in addition to <i><b>uisetfont</b></i>)<br />
<center><figure style="width: 264px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="FontComboBox" src="https://undocumentedmatlab.com/images/JIDE_FontComboBox.png" title="FontComboBox" width="264" height="259" /><figcaption class="wp-caption-text">FontComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/InsetsComboBox.html"><code>InsetsComboBox</code></a> – enables interactive definition of insets (margins)<br />
<center><figure style="width: 236px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="InsetsComboBox" src="https://undocumentedmatlab.com/images/JIDE_InsetsComboBox.png" title="InsetsComboBox" width="236" height="307" /><figcaption class="wp-caption-text">InsetsComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/TreeComboBox.html"><code>TreeComboBox</code></a>– a combo-box that displays selectable data in tree format (i.e., a hierarchy of items)<br />
<center><figure style="width: 148px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="TreeComboBox" src="https://undocumentedmatlab.com/images/JIDE_TreeComboBox.png" title="TreeComboBox" width="148" height="152" /><figcaption class="wp-caption-text">TreeComboBox</figcaption></figure></center></li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/TableComboBox.html"><code>TableComboBox</code></a> – a combo-box that displays selectable data in table format (i.e., multiple columns). The combo-box&#8217;s value is the selected table row&#8217;s left-most column value. Here&#8217;s an example:
<pre lang='matlab'>
data = num2cell([magic(3); -magic(3)]);  % needs to be a 2D cell-array
headers = {'one', 'two', 'three'};
tableModel = javax.swing.table.DefaultTableModel(data, headers);
jCombo = com.jidesoft.combobox.TableComboBox(tableModel);
[hjCombo, hContainer] = javacomponent(jCombo, [150,300,120,20], gcf);
</pre>
<p><center><figure style="width: 456px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="TableComboBox" src="https://undocumentedmatlab.com/images/JIDE_TableComboBox.png" title="TableComboBox" width="456" height="149" /><figcaption class="wp-caption-text">TableComboBox</figcaption></figure></center></li>
</ul>
<h3 id="GUI">Integrating in Matlab GUI</h3>
<p>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 <i><b>javacomponent</b></i> function:</p>
<pre lang='matlab'>
% 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)
</pre>
<p>Each combo-box control accepts its combo-list elements somewhat differently. For example, for <code>DateComboBox</code> we can specify the acceptable date-range (via <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DefaultDateModel.html"><code>DefaultDateModel</code></a>) and initial date, for a <code>FontComboBox</code> 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.<br />
In most cases, we can set the control handle&#8217;s <b>ActionPerformedCallback</b> to process a selection event (or modification of the combo-box value via direct editing in its integrated editbox):</p>
<pre lang='matlab'>set(hjCombo, 'ActionPerformedCallback', @myMatlabCallbackFcn);</pre>
<p>The selected item can in most cases be retrieved via</p>
<pre lang='matlab'>selectedItem = get(hjCombo,'SelectedItem');  % or: hjCombo.getselectedItem</pre>
<p>For some combo-boxes, non-numeric results may need to be converted into Matlab strings, via the <i><b>char</b></i> function:</p>
<pre lang='matlab'>selectedItem = char(selectedItem);</pre>
<p>Next week I plan to present a non-trivial customization of the <code>CheckBoxListComboBox</code> control.<br />
Additional discussion of JIDE&#8217;s combo-boxes, and JIDE controls in general, is available in Chapter 5 of my <a target="_blank" href="/matlab-java-book/">Matlab-Java Programming book</a>.<br />
If you need to integrate professional-looking controls such as these in your Matlab GUI, consider hiring my <a target="_blank" href="/consulting/">consulting services</a>.</p>
<h3 id="Caution">Caution</h3>
<p>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 <code>DateSpinnerComboBox</code> 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&#8217;s official <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/history/">change-log history</a>):</p>
<pre lang='matlab'>
>> com.jidesoft.utils.Lm.getProductVersion
ans =
3.4.1
</pre>
<p>Note that JIDE is a commercial product. We may not use it without JIDESoft&#8217;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.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/using-jide-combo-boxes">Using JIDE combo-boxes</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editable-combo-box" rel="bookmark" title="Editable combo-box">Editable combo-box </a> <small>Matlab's popup menu (combo-box) control is quite limited in its abilities. This article explains how we can work around these limitations. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="Date selection components">Date selection components </a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/using-jide-combo-boxes/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>treeTable</title>
		<link>https://undocumentedmatlab.com/articles/treetable?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=treetable</link>
					<comments>https://undocumentedmatlab.com/articles/treetable#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 06 Aug 2013 07:10:20 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<category><![CDATA[uitree]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4062</guid>

					<description><![CDATA[<p>A description of a sortable, groupable tree-table control that can be used in Matlab is provided. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/treetable">treeTable</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Since Matlab 7.0 (R14), Matlab has included a built-in GUI table control (<i><b>uitable</b></i>), at first as a <a target="_blank" href="/articles/legend-semi-documented-feature/#Semi-documented">semi-documented</a> function and in release 7.6 (R2008a) as a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/uitable.html">fully-documented</a> function. Useful as this control is, it lacks many features that are expected in modern GUIs, including sorting, filtering, cell-specific appearance and behavior, gridline customization etc. In <a target="_blank" href="/articles/tag/uitable/">past articles</a> I have explained how <i><b>uitable</b></i> can be customized to achieve a more professional-looking table. I expanded on this in my <a target="_blank" href="/matlab-java-book/">book</a> and my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a>.<br />
Today I explain how a grouping hierarchy can be achieved in a table control that can be used in Matlab GUI. Such a control, which is a combination of a <a target="_blank" href="/articles/uitree/"><i><b>uitree</b></i></a> and <i><b>uitable</b></i>, is typically called a <i>tree-table</i>. We can find numerous examples of it in everyday usage. I have encapsulated the functionality in a utility called <i><b>treeTable</b></i> on the Matlab File Exchange (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/42946-treetable-create-a-sortable-table-control-with-collapsible-row-groups">#42946</a>). The utility is provided with full source code and open-source license, and readers are welcome to use and modify it. A detailed explanation of the technicalities follows below, but if you&#8217;re just interested in having a sortable, rearrangeable, customizable, groupable table control, then all you need to do is download and use the utility.<br />
<figure style="width: 407px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="treeTable utility" src="https://undocumentedmatlab.com/images/treeTable.jpg" title="treeTable utility" width="407" height="364" /><figcaption class="wp-caption-text">treeTable utility</figcaption></figure></p>
<pre lang='matlab'>
headers = {'ID','Label','Logical1','Logical2','Selector','Numeric'};
data = {1,'M11',true, false,'One', 1011;  ...
        1,'M12',true, true, 'Two', 12;   ...
        1,'M13',false,false,'Many',13.4; ...
        2,'M21',true, false,'One', 21;  ...
        2,'M22',true, true, 'Two', 22;   ...
        3,'M31',true, true, 'Many',31;   ...
        3,'M32',false,true, 'One', -32;  ...
        3,'M33',false,false,'Two', 33; ...
        3,'M34',true, true, 'Many',34;  ...
};
selector = {'One','Two','Many'};
colTypes = {'label','label','char','logical',selector,'double'};
colEditable = {true, true, true, true, true}
icons = {fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/file_open.png'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/foldericon.gif'), ...
}
% Create the table in the current figure
jtable = treeTable('Container',gcf, 'Headers',headers, 'Data',data, ...
                   'ColumnTypes',colTypes, 'ColumnEditable',colEditable, ...
                   'IconFilenames',icons, 'Groupable',true, 'InteractiveGrouping',false);
% Collapse Row #6, sort descending column #5 (both are 0-based)
jtable.expandRow(5,false);  % 5=row #6; false=collapse
jtable.sortColumn(4,true,false);  % 4=column #5; true=primary; false=descending
</pre>
<p><span id="more-4062"></span></p>
<h3 id="implementation">The basic implementation concept</h3>
<p>Unfortunately, <i><b>uitable</b></i> as-is cannot be customized to have groupable rows. It derives from JIDE&#8217;s <code>SortableTable</code>, rather than one of its groupable derived classes. On the other hand, <i><b>uitree</b></i> (<i>don&#8217;t you agree that after a decade of this so-useful function being semi-documented it ought to be made official?</i>) uses a different class hierarchy outside <code>com.jidesoft.grid</code>, and so it cannot be easily customized to display rows (as opposed to simple labels).<br />
These limitations mean that we cannot use <i><b>uitable</b></i> or <i><b>uitree</b></i> and need to use a custom component. Luckily, such a component is available in all Matlab installations, on all platforms. It is part of the grid components package, on which Matlab GUI has relied for many years, by <a target="_blank" rel="nofollow" href="http://www.jidesoft.com">JIDE Software</a>. JIDE Grids is a collection of components that extend the standard Java Swing <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">JTable</a> component, and is included in each Matlab installation (<i>/java/jarext/jide/jide-grids.jar</i> under the Matlab root). I discussed <a target="_blank" href="/articles/tag/jide/">multiple JIDE controls</a> in this blog over the years. You can find further details on JIDE Grids in the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf">Developer Guide</a> and the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/">Javadoc documentation</a>.<br />
In fact, there are no less than three different components that we could use in our case: <code>TreeTable</code>, <code>GroupTable</code> and <code>HierarchicalTable</code>:<br />
<center><figure style="width: 417px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="JIDE Grids class hierarchy (we normally use only one of the marked classes)" src="https://undocumentedmatlab.com/images/JIDE_Grids.png" title="JIDE Grids class hierarchy (we normally use only one of the marked classes)" width="417" height="233"/><figcaption class="wp-caption-text">JIDE Grids class hierarchy (we normally use only one of the marked classes)</figcaption></figure></center><br />
Note that we cannot use <code>PropertyTable</code> since that component is limited to only two columns. This is perfect for presenting property names and values, which is the reason it is used by Matlab&#8217;s <i><b>inspect</b></i> function and my generic <a target="_blank" href="/articles/propertiesgui/"><i><b>propertiesGUI</b></i> utility</a> or Levente Hunyadi&#8217;s <a target="_blank" href="/articles/jide-property-grids/">Property Grid utility</a>. But in this case we wish to display a general multi-column table, so <code>PropertyTable</code> is a no-go.<br />
<code>TreeTable</code> and <code>GroupTable</code> enable data rows that have similar type (class), whereas <code>HierarchicalTable</code> enables more flexibility, by allowing display of any component type (including full tables) in child rows. This flexibility comes with a price that customizing a <code>HierarchicalTable</code> is more difficult than <code>TreeTable</code> or <code>GroupTable</code>. These latter two components are quite similar; we use <code>GroupTable</code>, which extends <code>TreeTable</code> with the ability to automatically group rows that have the same value in a certain column.</p>
<h3 id="model">Data model</h3>
<p>The above-mentioned table classes all derive from <code>SortableTable</code> (which also underlies <i><b>uitable</b></i>). Unfortunately, something in the Matlab-Java interface breaks the ability of the JIDE table classes (or rather, their data model) to understand numeric values for what they are. As a result, sorting columns is done lexically, i.e. &#8220;123&#8221; &lt; &#8220;34&#8221; &lt; &#8220;9&#8221;. To fix this, I&#8217;ve included a custom Java table model (<code>MultiClassTableModel</code>) with the <i><b>treeTable</b></i> utility, which automatically infers the column type (class) based on the value in the top row (by overriding the <i>getColumnClass()</i> method).<br />
Using this new class is pretty easy:</p>
<pre lang='matlab'>
% Create the basic data-type-aware model using our data and headers
javaaddpath(fileparts(mfilename('fullpath')));  % add the Java class file to the dynamic java class-path
model = MultiClassTableModel(data, headers);  % data=2D cell or numeric array; headers=cell array of strings
% Wrap the standard model in a JIDE GroupTableModel
com.mathworks.mwswing.MJUtilities.initJIDE;  % initialize JIDE
model = com.jidesoft.grid.DefaultGroupTableModel(model);
model.addGroupColumn(0);  % make the first column the grouping column
model.groupAndRefresh;  % update the model data
% Use the generated model as the data-model of a JIDE GroupTable
jtable = eval('com.jidesoft.grid.GroupTable(model);');  % prevent JIDE alert by run-time (not load-time) evaluation
jtable = handle(javaObjectEDT(jtable), 'CallbackProperties');  % ensure that we're using EDT
% Enable multi-column sorting
jtable.setSortable(true);
% Present the tree-table within a scrollable viewport on-screen
scroll = javaObjectEDT(JScrollPane(jtable));
[jhscroll,hContainer] = javacomponent(scroll, tablePosition, hParent);
set(hContainer,'units', 'normalized','pos',[0,0,1,1]);  % this will resize the table whenever its container is resized
</pre>
<p>Here, <em>com.mathworks.mwswing.MJUtilities.initJIDE</em> is called to initialize JIDE&#8217;s usage within Matlab. Without this call, we may see a JIDE warning message in some Matlab releases. We only need to <em>initJIDE</em> once per Matlab session, although there is no harm in repeated calls.<br />
<i><b>javacomponent</b></i> is the undocumented built-in Matlab function that adds Java Swing components to a Matlab figure, using the given dimensions and parent handle. I discussed it <a target="_blank" href="/articles/javacomponent/">here</a>.</p>
<h3 id="callbacks">Callbacks</h3>
<p>There are two main callbacks that can be used with <i><b>treeTable</b></i>:</p>
<ul>
<li>table data update &#8211; this can be set by uncommenting line #237 of <i>treeTable.m</i>:
<pre lang='matlab'>set(handle(getOriginalModel(jtable),'CallbackProperties'), 'TableChangedCallback', {@tableChangedCallback, jtable});</pre>
<p>which activates the sample <code>tableChangedCallback()</code> function (lines #684-694). Naturally, you can also set your own custom callback function.</p>
<pre lang='matlab'>
% Sample table-editing callback
function tableChangedCallback(hModel,hEvent,jtable)
    % Get the modification data
    modifiedRow = get(hEvent,'FirstRow');
    modifiedCol = get(hEvent,'Column');
    label   = hModel.getValueAt(modifiedRow,1);
    newData = hModel.getValueAt(modifiedRow,modifiedCol);
    % Now do something useful with this info
    fprintf('Modified cell %d,%d (%s) to: %s\n', modifiedRow+1, modifiedCol+1, char(label), num2str(newData));
end  % tableChangedCallback
</pre>
</li>
<li>row selection update &#8211; this is currently enabled in line #238 of <i>treeTable.m</i>:
<pre lang='matlab'>set(handle(jtable.getSelectionModel,'CallbackProperties'), 'ValueChangedCallback', {@selectionCallback, jtable});</pre>
<p>which activates the sample <code>selectionCallback()</code> function (lines #696-705). Naturally, you can also set your own custom callback function.</p>
<pre lang='matlab'>
% Sample table-selection callback
function selectionCallback(hSelectionModel,hEvent,jtable)
    % Get the selection data
    MinSelectionIndex  = get(hSelectionModel,'MinSelectionIndex');
    MaxSelectionIndex  = get(hSelectionModel,'MaxSelectionIndex');
    LeadSelectionIndex = get(hSelectionModel,'LeadSelectionIndex');
    % Now do something useful with this info
    fprintf('Selected rows #%d-%d\n', MinSelectionIndex+1, MaxSelectionIndex+1);
end  % selectionCallback
</pre>
</li>
</ul>
<h3 id="features">Some useful features of <i>treeTable</i></h3>
<p><center><figure style="width: 342px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="treeTable with InteractiveGrouping, multi-column sorting, column rearranging" src="https://undocumentedmatlab.com/images/treeTable_InteractiveGrouping.jpg" title="treeTable with InteractiveGrouping, multi-column sorting, column rearranging" width="342" height="366" /><figcaption class="wp-caption-text">treeTable with interactive grouping, multi-column sorting, column rearranging</figcaption></figure></center></p>
<ul>
<li>Sortable columns (including numeric columns)</li>
<li>Rearrangeable columns (drag headers left/right)</li>
<li>Auto-fit the table columns into the specified container width</li>
<li>Manually resize columns by dragging the column divider gridlines (not just the header dividers as in <i><b>uitable</b></i>)</li>
<li>Flat or groupable table, based on the specified <b>Groupable</b> parameter (default=true)</li>
<li>Ability to interactively group columns (just like Microsoft Outlook) using the <b>InteractiveGrouping</b> parameter (default=false)</li>
<li>Selector cells only show the drop-down arrow of the currently-selected cell (unlike <i><b>uitable</b></i> which shows it for all the column cells)</li>
<li>Selector cells enable editing, unlike <i><b>uitable</b></i> that only enables selecting among pre-defined values</li>
<li>Ability to attach user-defined icons for the leaf rows and the grouping rows (expanded/collapsed)</li>
<li>Easily attach custom cell editors or renderers to any table column (see my <a target="_blank" href="/matlab-java-book/">book</a> and my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a> for details)</li>
</ul>
<p>All of these features can be turned on/off using the control&#8217;s properties. Again, see my book or report for details (or <a target="_blank" href="/consulting/">ask me</a> to do it for you&#8230;).<br />
I remind readers that I will be visiting clients in Austria (Vienna, Salzburg) and Switzerland (Zurich) in August 18-29. If you live in the area, I will be happy to meet you to discuss how I could bring value to your needs, as consultant, contractor or trainer (<a target="_blank" href="/articles/sparse-data-math-info/#visit">more details</a>).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/treetable">treeTable</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/treetable/feed</wfw:commentRss>
			<slash:comments>90</slash:comments>
		
		
			</item>
		<item>
		<title>propertiesGUI</title>
		<link>https://undocumentedmatlab.com/articles/propertiesgui?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=propertiesgui</link>
					<comments>https://undocumentedmatlab.com/articles/propertiesgui#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Jan 2013 18:00:44 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Levente Hunyadi]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3511</guid>

					<description><![CDATA[<p>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/propertiesgui">propertiesGUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiinspect" rel="bookmark" title="uiinspect">uiinspect </a> <small>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I presented a detailed explanation of the <a target="_blank" href="/articles/uiinspect/"><i><b>uiinspect</b></i> utility</a>, which displays a GUI listing all the properties, callbacks and internal methods of an inspected object. Something like Matlab&#8217;s <i><b>inspect</b></i> tool on steroids. I explained that <i><b>uiinspect</b></i> uses <code>com.mathworks.mlwidgets.inspector.PropertyView</code>, which in turn uses JIDE&#8217;s <a target="_blank" href="/articles/jide-property-grids/">PropertyTable</a>. <code>PropertyView</code> automatically extracts the inspected object&#8217;s properties and displays them using a corresponding renderer in the <code>PropertyTable</code>.<br />
<figure style="width: 508px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="propertiesGUI demo" src="https://undocumentedmatlab.com/images/propertiesGUI.gif" title="propertiesGUI demo" width="508" height="603" /><figcaption class="wp-caption-text">propertiesGUI demo</figcaption></figure><br />
We often need to present a non-object Matlab construct. For example, it is very common to store an application&#8217;s configuration properties in a struct (using Matlab objects is often impractical and unwarranted) &#8212; it would be very useful to present this configuration dynamically, without having to programmatically scan all struct fields and build a dedicated GUI table. Unfortunately, <code>PropertyView</code> cannot automatically retrospect Matlab structs, which is the reason that the built-in <i><b>inspect</b></i> function fails for such objects. In the general case, we may wish to present a <code>PropertyTable</code> using row-specific renderers and editors, when we have such an un-inspectable object (struct, cell array etc.), or even for a dynamically-created table of properties that is not stored in any single object.<br />
Another limitation of <code>PropertyView</code> is that it immediately assigns updated property values to the inspected object, without allowing any sanity checks to be conducted on the new values, and without enabling the user to cancel property changes.<br />
Last but not least, <code>PropertyView</code> does not enable users to easily modify the way that certain properties are presented. Boolean properties (true/false) always use a checkbox cell-renderer/editor, while we may wish to display a string (on/off) or combo-box instead.<br />
In short, <code>PropertyView</code> is great unless you want to customize stuff, or do something slightly out-of-the-ordinary.<br />
Enter <i><b>propertiesGUI</b></i>, the subject of today&#8217;s article.<br />
<span id="more-3511"></span></p>
<h3 id="utility">The propertiesGUI utility</h3>
<p><i><b>propertiesGUI</b></i>, which can be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/38864-propertiesgui-display-properties-in-an-editable-context-aware-table">downloaded</a> from the Matlab File Exchange, presents a generic solution to this problem. <i><b>propertiesGUI</b></i> is based on Levente Hunyadi&#8217;s articles <a target="_blank" href="/articles/tag/levente-hunyadi/">here</a> back in 2010, and on his <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28732-property-grid-using-jide-implementation">&#8220;Property grid&#8221; utility</a> on the File Exchange.<br />
<i><b>propertiesGUI</b></i> expects the following syntax:</p>
<pre lang='matlab'>[hPropsPane, parameters] = propertiesGUI(hParent, parameters)</pre>
<p>where:</p>
<ul>
<li><code>hParent</code> (input) is an optional handle of a parent GUI container (figure/uipanel/uitab) in which the properties table will appear. If missing or empty or 0, the table will be shown in a new modal dialog window; otherwise it will be embedded in the parent container.</li>
<li><code>parameters</code> (input) is an optional struct or object with data fields. The fields are processed separately to determine their corresponding cell renderer and editor. If <code>parameters</code> is not specified, then the global <code>test_data</code> will be used. If <code>test_data</code> is also empty, then a demo of several different data types will be used.</li>
<li><code>hPropsPane</code> (output) is the handle of the generated properties panel widget, which can be customized to display field descriptions, toolbar, etc.</li>
<li><code>parameters</code> (output) is the resulting (possibly-updated) parameters struct. Naturally, this is only relevant in case of a modal dialog.</li>
</ul>
<p>When passing the properties in an input <code>parameters</code> struct, <i><b>propertiesGUI</b></i> automatically inspects each struct field and assigns a corresponding cell-editor with no description and a field label that reflects the field name. The properties are automatically set as modifiable (editable) and assigned a default callback function (<i>propUpdatedCallback</i> sub-function).<br />
The global <code>test_data</code> variable is updated internally when the &lt;OK&gt; button is clicked. It is meant to enable easy data passing between the properties GUI and other application component. Using global vars is generally <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Action_at_a_distance_%28computer_programming%29">discouraged</a> as bad programming, but it simplifies GUI component interaction and has performance advantages. In this specific case I decided that the benefits of simplicity outweigh the pedagogical aspects. After all, <i><b>propertiesGUI</b></i> is meant to illustrate how to customize/use a properties pane, not to teach GUI programming best practices. In your real-world application you should consider using other information-sharing mechanisms (<i><b>getappdata</b></i> or <i><b>guidata</b></i>, for example).</p>
<h3 id="demo">Usage demo</h3>
<p>For an illustration of <i><b>propertiesGUI</b></i>, simply run it without any parameters to display its demo (see screenshot above):</p>
<pre lang='matlab'>propertiesGUI;</pre>
<p>This creates (in the <i>demoParameters</i> sub-function) the following demo <code>parameters</code> struct:</p>
<pre lang='matlab'>
      floating_point_property: 3.14159265358979
      signed_integer_property: 12
    unsigned_integer_property: 12
                flag_property: 1
                file_property: ''
              folder_property: 'C:\Yair'
                text_property: 'Sample text'
        fixed_choice_property: {'Yes'  'No'  'Maybe'}
     editable_choice_property: {'Yes'  'No'  'Maybe'  ''}
                date_property: [1x1 java.util.Date]
        another_date_property: 734895.957829132
                time_property: '22:59:16'
            password_property: '*****'
          IP_address_property: '10.20.30.40'
                  my_category: [1x1 struct]
               color_property: [0.4 0.5 0.6]
       another_color_property: [1x1 java.awt.Color]
</pre>
<h3 id="template">A template for customization</h3>
<p><i><b>propertiesGUI</b></i> is meant to be used either as stand-alone, or as a template for customization. For example, we can attach a unique description to each property that will be shown in an internal sub-panel: see the <i>customizePropertyPane</i> and <i>preparePropsList</i> sub-functions.<br />
We can have specific control over each property&#8217;s description, label, editability, cell-editor and callback function. See the <i>preparePropsList</i> sub-functions for some examples. Additional cell-editors/renderers can be added in the <i>newProperty</i> sub-function.<br />
Specific control over the acceptable property values can be achieved by entering custom code into the <i>checkProp</i> sub-function. For example, <i>checkProp</i> already contains skeleton code to highlight missing mandatory field values in yellow, and non-editable properties in gray (see highlighted lines; the necessary modifications to make it work should be self-evident):</p>
<pre lang='matlab' highlight="9-11,13-14">
function isOk = checkProp(prop)
  isOk = true;
  oldWarn = warning('off','MATLAB:hg:JavaSetHGProperty');
  warning off MATLAB:hg:PossibleDeprecatedJavaSetHGProperty
  propName = get(prop, 'UserData');
  renderer = com.jidesoft.grid.CellRendererManager.getRenderer(get(prop,'Type'), get(prop,'EditorContext'));
  warning(oldWarn);
  mandatoryFields = {};  % TODO - add the mandatory field-names here
  if any(strcmpi(propName, mandatoryFields)) && isempty(get(prop,'Value'))
      propColor = java.awt.Color.yellow;
      isOk = false;
  elseif ~prop.isEditable
      %propColor = java.awt.Color.gray;
      propColor = renderer.getBackground();
  else
      propColor = java.awt.Color.white;
  end
  renderer.setBackground(propColor);
end  % checkProp
</pre>
<p>So if we wish to check the validity of the input or user updates, we simply need to enter the relevant checks into <i>checkProp</i>.<br />
Additional control over the appearance and functionality can be achieved via the <code>hPropsPane</code> reference that is returned by <i><b>propertiesGUI</b></i>.</p>
<div id="example"></div>
<p>As an example for such customizations, here is a variant of the properties pane, embedded within a <a target="_blank" href="/articles/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a> panel. Note the unique description of the properties, and the absence of the OK/Cancel buttons:<br />
<center><figure style="width: 500px" class="wp-caption aligncenter"><img decoding="async" alt="Properties panel Integrated within a GUI" src="https://undocumentedmatlab.com/images/Champ_animated.gif" title="Properties panel Integrated within a GUI" width="500" /><figcaption class="wp-caption-text">Properties panel Integrated within a GUI</figcaption></figure></center></p>
<h3 id="TODO">TODO</h3>
<p>Even as a template for customization, <i><b>propertiesGUI</b></i> is still far from perfect. Some potential items on my TODO list for this utility include:</p>
<ul>
<li>Fix the renderer/editor for numeric and cell arrays</li>
<li>Enable more control over appearance and functionality via input parameters (for example: display or hide the OK/Cancel buttons)</li>
<li>Add additional built-in cell editors/renderers: time, slider, point, rectangle (=position), font, &#8230;</li>
</ul>
<p>Do you find <i><b>propertiesGUI</b></i> useful in your work? If so then please share your experience in a comment <a href="/articles/propertiesgui/#respond">below</a>. Suggestions for improvement of the utility will also be gladly accepted.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/propertiesgui">propertiesGUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiinspect" rel="bookmark" title="uiinspect">uiinspect </a> <small>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/propertiesgui/feed</wfw:commentRss>
			<slash:comments>34</slash:comments>
		
		
			</item>
		<item>
		<title>uiinspect</title>
		<link>https://undocumentedmatlab.com/articles/uiinspect?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uiinspect</link>
					<comments>https://undocumentedmatlab.com/articles/uiinspect#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 23 Jan 2013 18:00:09 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Dot-Net]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3477</guid>

					<description><![CDATA[<p>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiinspect">uiinspect</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/propertiesgui" rel="bookmark" title="propertiesGUI">propertiesGUI </a> <small>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>After several years in which I have mentioned my <i><b>uiinspect</b></i> utility in posts, I figured it is high time to actually describe this utility in detail.<br />
<figure style="width: 500px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="uiinspect in action (Java, HG, COM)" src="https://undocumentedmatlab.com/images/uiinspect.gif" title="uiinspect in action (Java, HG, COM)" width="500" height="387"/><figcaption class="wp-caption-text">uiinspect in action (Java, HG, COM)</figcaption></figure><br />
<i><b>uiinspect</b></i>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">downloadable</a> from the Matlab file Exchange, is a Matlab GUI utility that inspects the specified object and provides detailed information about its super-classes, methods, properties, static fields and callbacks in a unified Matlab window. <i><b>uiinspect</b></i> works on a very wide variety of inputs: Matlab/Java/Dot-Net class names and class objects; COM/DCOM objects, Handle Graphics handles etc.<br />
In essence, <i><b>uiinspect</b></i> incorporates the information presented by the following built-in Matlab functions: <i><b>inspect</b></i>, <i><b>get</b></i>, and <i><b>methodsview</b></i>. <i><b>uiinspect</b></i> also presents additional aspects that are not available in any built-in Matlab function (for example, inheritance information, undocumented hidden properties, properties meta-data, grouping of callbacks by type).<br />
<i><b>uiinspect</b></i> displays hidden properties and fields that are not normally displayed in Matlab (see my related <a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/">getundoc</a> utility). Property meta-data such as type, accessibility, visibility and default value are also displayed. Object properties and callbacks may be modified interactively within the <i><b>uiinspect</b></i> window.<br />
Of over 40 utilities that I have so-far submitted to the File Exchange, <i><b>uiinspect</b></i> is one of my most complex (together with <a target="_blank" href="/articles/findjobj"><i><b>findjobj</b></i></a>). It has undergone 24 revisions since its initial release in 2007. The latest revision has nearly 3000 source-code lines, of which 75% are code lines, 20% are comment lines and the rest are empty spacer lines. That&#8217;s a pretty complex utility to describe, and it relies on plenty of undocumented aspects, so today&#8217;s post will only highlight the important aspects. Readers are more than welcome to have a look at the source code for additional details. It is pretty-well documented, if I may say so myself.<br />
<span id="more-3477"></span></p>
<h3 id="syntax">Usage syntax</h3>
<p>The basic syntax is:</p>
<pre lang='matlab'>hFig = uiinspect(handle)</pre>
<p>Examples:</p>
<pre lang='matlab'>
hFig = uiinspect(0);                         % the root handle
hFig = uiinspect(handle(0));
hFig = uiinspect(gcf);                       % current figure
hFig = uiinspect(handle(gcf));
uiinspect('java.lang.String');               % Java classname
uiinspect(java.lang.String('yes'));          % Java object
uiinspect(get(gcf,'JavaFrame'));             % Java object
uiinspect(classhandle(handle(gcf)));         % UDD class object
uiinspect(findprop(handle(gcf),'MenuBar'));  % UDD property
uiinspect(actxserver('Excel.Application'));  % COM object
uiinspect(Employee)                          % Matlab class object
uiinspect(?handle)                           % Matlab metaclass object
uiinspect('meta.class')                      % Matlab class name
uiinspect(System.DateTime.Now)               % Dot-Net object
</pre>
<p><i><b>uiinspect</b></i> returns a handle to the created figure window. <i><b>uiinspect</b></i> opens a regular Matlab figure window which may be accessed via hFig (unlike Matlab&#8217;s <i><b>methodsview</b></i> and <i><b>inspect</b></i> functions which open Java frame that is not accessible from Matlab).<br />
Unlike Matlab&#8217;s functions, multiple <i><b>uiinspect</b></i> windows can be opened simultaneously, for different objects. The differentiation is done based on figure title, which contains the inspected object&#8217;s name (if available) and its class &#8211; reinspecting the same object will reuse the existing figure window, but in all other cases a new figure window will be created.</p>
<h3 id="panels">Main panels</h3>
<p><i><b>uiinspect</b></i> includes the following information panels, that shall be described separately below:</p>
<ul>
<li>Class information (including superclasses, if applicable)</li>
<li>Methods (for objects) or graphic handle hierarchy (for Handle Graphics)</li>
<li>Callbacks (where applicable)</li>
<li>Inspectable properties</li>
<li>Other properties plus full meta-data (where applicable)</li>
</ul>
<p>The panels are fully resizable. We can drag the divider lines up/down or left/right and the contents automatically adjust accordingly. Each panel has a minimal viewable width/height, and the dividers cannot be dragged to squeeze the panels below these minimums &#8211; they can only be minimized, which hides the relevant panel entirely. To minimize a panel, simply click the relevant small arrow mark on the divider. The opposite arrow mark next to it maximizes the panel, effectively minimizing the panel on the other side. Once minimized/maximized, the divider can be restored by simply clicking it once, or by dragging it (again, panel minimum sizes apply).<br />
<i><b>uiinspect</b></i> only uses Java panels, so implementing the dividers required use of the simple <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html">JSplitPane</a>. In a general case where we might wish to embed Matlab graphs in one of the side panels, we would need to employ a more sophisticated solution (see my <a target="_blank" href="/articles/uisplitpane/">UISplitPane</a> utility).</p>
<h3 id="class">Class information</h3>
<p>The top-left panel displays a label with information about the object&#8217;s class and super-classes inheritance (where applicable).<br />
The class name itself is hyper-linked to the class&#8217;s documentation: if this is a standard Java class, then to the official online javadoc for this class which opens up in Matlab&#8217;s internal web browser. In fact, since different Matlab releases use different JVM versions (1.3 through 1.6), the link points to the documentation page corresponding to the JVM version actually used.<br />
If the class is non-Java, the hyperlink displays the class&#8217;s help section in Matlab&#8217;s Command Window / console. The panel&#8217;s tooltip displays the same information in a slightly different manner.<br />
The hyperlink in the label is actually an optical illusion. In fact, the entire label is hyper-linked, and clicking any part of it will display the relevant documentation (a similar optical illusion is used to display the hyperlink at the footer of the utility window). The illusion is achieved using <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">Matlab&#8217;s HTML formatting</a>, where the part of the label string consisting of the class name is underlined. The cursor was dynamically modified to a pointed hand-finger when the mouse hovers over the label, using the following simple Java-based command:</p>
<pre lang='matlab'>methodsLabel.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));</pre>
<p>Special treatment is done to extract the class&#8217;s superclass, the interfaces that it implements and any possible class qualifiers (for example, &#8220;final&#8221;).<br />
For those interested to dig within the code, all this is done in <i><b>uiinspect</b></i>&#8216;s <i>getMethodsPane</i> function.<br />
Next to the class label, a checkbox is presented (&#8220;Extra&#8221;). Clicking this checkbox displays additional meta-data information (qualifiers, interrupts and inheritance) in the methods pane beneath. Not all classes have all these extra meta-data fields &#8211; only the relevant extra meta-information fields are displayed. If there are is extra meta-data, then the checkbox is not displayed. This is done in the <i>getMethodsTable</i> function.</p>
<h3 id="methods">Methods or HG hierarchy panel</h3>
<p>The utility&#8217;s main panel displays either a table of methods (functions) for a class object, or a tree hierarchy for an HG handle.</p>
<h4 id="class-methods">Class object methods</h4>
<p>The methods table takes the information from the <i>getObjMethods</i> function, which is an adaptation of Matlab&#8217;s built-in <i><b>methodsview</b></i> function. Part of the adaptation is to hyperlink all class references (used in the methods&#8217; inputs, outputs and meta-data), such that clicking them will open new corresponding <i><b>uiinspect</b></i> windows.<br />
<figure style="width: 468px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Class object methods panel" src="https://undocumentedmatlab.com/images/uiinspect_methods.gif" title="Class object methods panel" width="468" height="219" /><figcaption class="wp-caption-text">Class object methods panel</figcaption></figure><br />
The methods data is displayed within a non-editable Java table (in the <i>getMethodsTable</i> function) that auto-resizes the columns. The table columns are sortable, even sortable on multiple columns by CTRL-clicking (<i><b>methodsview</b></i> allows only simple sorting). This is done using JIDE&#8217;s <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/TreeTable.html">TreeTable</a> component. The table is placed within a scroll-pane having <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html#scrollbars">automatic scrollbars</a> that only appear as needed.<br />
The table&#8217;s <b>MouseMovedCallback</b> property is set to <i>tbMouseMoved</i>, which updates the mouse cursor (either regular or pointed finger) based on the current mouse position in the table (whether over a hyperlinked cell or not).<br />
The table&#8217;s <b>MousePressedCallback</b> property is set to <i>tbMousePressed</i>, which opens new <i><b>uiinspect</b></i> figure windows for the hyperlinked classes (if any) in the clicked cell.</p>
<h4 id="HG-hierarchy">HG hierarchy tree</h4>
<p>For HG handles, <i>getHandleTree</i> creates a Java tree that displays the hierarchy of HG children (as recursively reported by any HG handle&#8217;s <b>Children</b> property). For convenience, I have chosen to use the built-in component <code>com.mathworks.hg.peer.UITreePeer</code> that underlies the built-in <a target="_blank" href="/articles/uitree/"><i><b>uitree</b></i></a> function. For performance reasons, the tree is not fully evaluated: the inspected handle&#8217;s <b>Parent</b> is set as the tree&#8217;s <b>Root</b>. The root node is expanded to get all the parent&#8217;s <b>Children</b> (i.e., the inspected handle&#8217;s siblings), and then the inspected handle&#8217;s tree node is again expanded to display its direct descendents.<br />
<figure style="width: 283px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Normal dynamic HG handle tooltip" src="https://undocumentedmatlab.com/images/uiinspect_HG_tooltip1.gif" title="Normal dynamic HG handle tooltip" width="283" height="115" /><figcaption class="wp-caption-text">Normal dynamic HG handle tooltip</figcaption></figure><br />
A <b>MouseMovedCallback</b> is set on the tree to process mouse hover events in the <i>treeMouseMovedCallback</i> function. This function updates the tree tooltip dynamically, in the sense that it presents a different tooltip for different handles (tree nodes).<br />
Invalid HG handles (this can happen if the HG handle was deleted since the time that <i><b>uiinspect</b></i> generated the tree) are displayed with a special warning message.<br />
<figure style="width: 350px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Invalid HG handle tooltip" src="https://undocumentedmatlab.com/images/uiinspect_HG_tooltip2.gif" title="Invalid HG handle tooltip" width="350" height="44" /><figcaption class="wp-caption-text">Invalid HG handle tooltip</figcaption></figure><br />
This dynamic tree behavior is achieved by storing the relevant handle information in the <b>UserData</b> of the different tree nodes. Unfortunately, starting in R2012a, Matlab has made a change in the internal support of Java objects, and the <b>UserData</b> property is no longer available. Such a case is detected and the data is stored in the tree nodes&#8217; <b>ApplicationData</b> property instead (using <i><b>setappdata</b>(node,&#8217;userdata&#8217;,&#8230;)</i> ).<br />
<figure style="width: 630px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Dynamic context (right-click) menu" src="https://undocumentedmatlab.com/images/uiinspect3.gif" title="Dynamic context (right-click) menu" width="630" height="488" /><figcaption class="wp-caption-text">Dynamic context (right-click) menu</figcaption></figure><br />
A <b>MousePressedCallback</b> is set on the tree to process context (right-click) events in the <i>treeMousePressedCallback</i> function. The context-menu is also dynamic, in the sense that it presents a different context menu for different handles (tree nodes), again based on their user-data.<br />
Left-clicking a node is not processed by <i>treeMousePressedCallback</i>, but rather by the tree&#8217;s <b>NodeSelectedCallback</b> which is processed in <i>nodeSelected</i>, and by <b>NodeExpandedCallback</b> which is processed by <i>nodeExpanded</i>. <i>nodeSelected</i> reloads <i><b>uiinspect</b></i> for the selected handle; <i>nodeExpanded</i> merely displays the expanded handle&#8217;s children.<br />
Since the &#8216;+&#8217; sign (which triggers <i>nodeExpanded</i>) and the handle icon (which triggers <i>nodeSelected</i>) are so close, we should be careful to click the &#8216;+&#8217;, otherwise the entire <i><b>uiinspect</b></i> window will reload the tree based on the clicked node&#8230; If anyone has a good idea how to solve this dilemma, then I&#8217;m all ears.<br />
Like the methods table, the tree is also placed in a dynamic scroll-pane that displays scrollbars only as needed.</p>
<h3 id="callbacks">Callbacks panel</h3>
<p>The callbacks panel, computed in <i>getCbsData</i> is based on a reflection of the object&#8217;s data as reported by the undocumented built-in <i><b>classhandle</b></i> function. I aggregate all the object&#8217;s events, as well as all the object property names that end with &#8216;Fcn&#8217; or &#8216;Callback&#8217;. This takes care (I hope) of all the different manners by which different kinds of objects raise events that are trappable in Matlab callbacks. Specifically, it takes care of Java/Matlab classes as well as HG handles and COM objects. If anyone thinks that I have forgotten something, please let me know.<br />
The <i>getCbsPane</i> function then displays the callbacks data (callbacks&#8217; property name and value) in a Java table (JIDE <a target="_blank" href="/articles/jide-property-grids/">PropertyTable</a>, JIDE TreeTable, or failing those a simple JTable).<br />
<figure style="width: 551px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Modifiable object callbacks" src="https://undocumentedmatlab.com/images/uiinspect_callbacks.gif" title="Modifiable object callbacks" width="551" height="337" /><figcaption class="wp-caption-text">Modifiable object callbacks</figcaption></figure><br />
The callbacks are automatically grouped by name into logical groups (in <i>getTreeData</i>). For example, all callbacks whose names start with &#8220;Mouse*&#8221; are grouped in the &#8220;Mouse callbacks&#8221; group. The last group is always called &#8220;Other callbacks&#8221; and contains all callbacks for which a matching sibling callback has not been found. The groups are automatically collapsed by default; if only a single group is found then this group is automatically opened (for example, in the case of <i><b>uiinspect</b>(0)</i> ).<br />
The callbacks table&#8217;s toolbar enables displaying the callbacks by groups or sorted alphabetically. It also has &#8220;expand&#8221; and &#8220;collapse&#8221; icons that affect all the groups.<br />
A checkbox next to the table&#8217;s toolbar enables hiding <a target="_blank" href="/articles/uicontrol-callbacks/">standard Java Swing callbacks</a>. This is important when we inspect Java controls and only wish to see its unique callbacks. When using this checkbox, red Java exceptions are sometimes displayed in the Matlab console &#8211; these are harmless and you can safely ignore them (I hope to find a way to prevent them one day).<br />
The table&#8217;s right column displays the callback properties values (if available). This column is editable and we can interactively modify any callback&#8217;s property. As shown, we can enter callback value in either of Matlab&#8217;s supported formats: string, function handle and (for non-COM objects only!) a cell array of function handle and additional data. An error message will be displayed if the callback value is invalid or cannot be set for some reason.<br />
If it is determined that there are no callbacks, then the callbacks panel is automatically minimized, to enable maximum space for the methods panel above it.</p>
<h3 id="inspector">Properties inspector panel</h3>
<p>The properties inspection panel, prepared in <i>getPropsPane</i>, is actually composed of two separate panes: the top pane uses the built-in Matlab component <code>com.mathworks.mlwidgets.inspector.PropertyView</code>, which in turn uses JIDE&#8217;s <a target="_blank" href="/articles/jide-property-grids/">PropertyTable</a>. <code>PropertyView</code> is the same component used by Matlab&#8217;s standard <i><b>inspect</b></i> function (that&#8217;s how I came to know it, if anyone wonders).<br />
<figure style="width: 351px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="uiinspect's property inspector table" src="https://undocumentedmatlab.com/images/PropertyTable.gif" title="uiinspect's property inspector table" width="351" height="216" /><figcaption class="wp-caption-text">uiinspect's property inspector table</figcaption></figure><br />
The benefit of using Matlab&#8217;s <code>PropertyView</code> component rather than JIDE&#8217;s <code>PropertyTable</code> is that <code>PropertyView</code> has the very useful method <i>setObject</i> which I use to point the component at the inspected object, which automatically infers its non-hidden properties and updates the table, saving me a lot of work.<br />
There are two drawbacks of using Matlab&#8217;s <code>PropertyView</code>:</p>
<ul>
<li><code>PropertyView</code> only displays non-hidden properties. One day when I have time, I intent to add the hidden properties to the resulting JIDE <code>PropertyTable</code>. But for now it only shows non-hidden properties.</li>
<li><code>PropertyView</code> causes a Matlab crash on some Matlab releases, in case <i><b>dbstop if error</b></i> is active (this can be replicated using Matlab&#8217;s standard <i><b>inspect</b></i>). I therefore regrettably need to disable this specific <i><b>dbstop</b></i>.</li>
</ul>
<p>I&#8217;ve been meaning to do these two fixes ever since I released <i><b>uiinspect</b></i> back in 2007, but for now that&#8217;s the way it is&#8230;<br />
The properties data is retrieved via the <i>getPropsData</i> function. This function uses the built-in Matlab functions <i><b>meta.class.fromName</b>(className)</i> and <i><b>metaclass</b>(classObject)</i> to get the class handle of Matlab classes (in <i>getMetaClass</i>); similarly, <i>loadClass</i> loads the class definition for a Java class. I inspect these class handles for their contained properties. I then use the <i><b>fieldnames</b></i> function to add static class fields, which are not standard properties (for example, &#8220;RED&#8221; is a static field of the <code>java.awt.Color</code> class).<br />
From the class handle, I retrieve the full definition of each property. This includes meta-data such as whether the property is regular or hidden (undocumented); settable or not; gettable or not; and any additional qualifiers (e.g., Sealed, Dependent, Constant, Abstract, Transient, Default (factory) value).<br />
<figure style="width: 450px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Object properties tooltip" src="https://undocumentedmatlab.com/images/uiinspect_properties1.gif" title="Object properties tooltip" width="450" height="297"/><figcaption class="wp-caption-text">Object properties tooltip</figcaption></figure><br />
We now have a list of all properties and static fields, and this is used to display the entire properties data in the properties panel&#8217;s title (&#8220;Inspectable object properties&#8221;) tooltip. This tooltip, created in <i>updateObjTooltip</i> and <i>getPropsHtml</i>, uses some fancy HTML formatting to display all the object&#8217;s properties and values, color- and font-style-coded to show which of the properties is read-only, hidden, undefined etc.<br />
<figure style="width: 495px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="The 'Other properties' meta-data table" src="https://undocumentedmatlab.com/images/uiinspect_properties2.gif" title="The 'Other properties' meta-data table" width="495" height="317" /><figcaption class="wp-caption-text">The 'Other properties' meta-data table</figcaption></figure><br />
The entire information is also displayed in the properties meta-data pane (&#8220;Other properties&#8221;) beneath JIDE&#8217;s inspector pane. Here we use a simple Java table to display the information in color-coding (gray for read-only properties; blue for static fields; red for irretrievable properties).<br />
Separate checkboxes enable displaying all properties (by default only the properties that are NOT displayed in JIDE&#8217;s inspector table are displayed); and whether or not to display the extra meta-data in the properties table (by default only the property name and current value are displayed).<br />
In some cases (e.g., Dot-Net objects), Matlab&#8217;s inspector does not know how to extract the property-bean information and so the <code>PropertyView</code> inspector is not shown, only the &#8220;other properties&#8221; table.<br />
Both JIDE&#8217;s inspector table and the &#8220;other properties&#8221; table enable the user to modify existing values. Note that in some cases Matlab prevents interactive update of some properties, and in some other cases I have seen Matlab hang when trying to update a few specific properties. But in most cases updating the value does work as expected.<br />
The combination of the inspector table, the meta-data table and the tooltip, enable users to fully understand the accessible properties of the inspected object. Of course, it would have been much better to merge the JIDE inspector table with the hidden properties (=additional rows) and meta-data (=additional columns). But let&#8217;s leave something for the future, shall we?</p>
<h3 id="update">Auto-update mechanism</h3>
<p><figure style="width: 519px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="uiinspect auto-update notice" src="https://undocumentedmatlab.com/images/uiinspect_update.gif" title="uiinspect auto-update notice" width="519" height="190" /><figcaption class="wp-caption-text">uiinspect auto-update notice</figcaption></figure><br />
<i><b>uiinspect</b></i> employs the same auto-update background mechanism used by <i><b>findjobj</b></i> &#8211; after presenting the GUI, the utility silently checks the File Exchange webpage to see whether any newer version of this utility has been uploaded. If so, then a popup notice is presented with the date and description of the latest version. The popup enables users to download the newer version into their Matlab path, or skip. There is also an option to skip the update and not to remind ever again.<br />
I find this background auto-update mechanism quite useful and generic. In fact, I uploaded it as a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/39993-checkVersion">separate File Exchange utility</a> today, following <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2012/12/14/a-conversation-about-managing-file-exchange-downloads/#comment-17358">Brett Shoelson&#8217;s suggestion</a> last month. You can find the underlying code in the <i>checkVersion</i> function.</p>
<h3 id="TODO">TODO</h3>
<ul>
<li>cleanup internal functions, remove duplicates etc.</li>
<li>link property objects to another <i><b>uiinspect</b></i> window for these objects</li>
<li>display object children (&#038; link to them) &#8211; COM/Java</li>
<li>find a way to merge the other-properties table with the inspector table (hidden props + meta-data)</li>
<li>find a way to use the inspector without disabling <i><b>dbstop if error</b></i></li>
<li>Fix: some fields generate a Java Exception from: <code>com.mathworks.mlwidgets.inspector.PropertyRootNode$PropertyListener$1$1.run</code></li>
<li>Fix: using the &#8220;Hide standard callbacks&#8221; checkbox sometimes issues Java Exceptions on the console</li>
<li>Fix: In HG tree view, sometimes the currently-inspected handle is not automatically selected</li>
</ul>
<p>I would be happy if anyone can help with any of these.</p>
<h3 id="conclusion">Conclusion</h3>
<p>I believe that this has been my longest blog post ever; certainly the one that I have labored most over. This correlates well with the <i><b>uiinspect</b></i> utility, which has been one of my most complex tasks. I&#8217;m guessing I must have invested 100-200 man-hours developing and improving it over the years.<br />
I hope you find <i><b>uiinspect</b></i> as useful and as fun as I do. I believe that its source-code is certainly worth reading if you are interested in any advanced Matlab GUI programming, showing how Java GUI components can be combined in Matlab. Go ahead and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">download <i><b>uiinspect</b></i></a> from the Matlab file Exchange.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiinspect">uiinspect</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/propertiesgui" rel="bookmark" title="propertiesGUI">propertiesGUI </a> <small>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uiinspect/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Uitable cell colors</title>
		<link>https://undocumentedmatlab.com/articles/uitable-cell-colors?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitable-cell-colors</link>
					<comments>https://undocumentedmatlab.com/articles/uitable-cell-colors#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 27 Oct 2011 01:51:53 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2476</guid>

					<description><![CDATA[<p>A few Java-based customizations can transform a plain-looking data table into a lively colored one. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-cell-colors">Uitable cell colors</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitab-colors-icons-images" rel="bookmark" title="Uitab colors, icons and images">Uitab colors, icons and images </a> <small>Matlab's semi-documented tab panels can be customized using some undocumented hacks...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A client recently asked me to develop an application that will help discover technical indicators for trading on the stock market. The application was very data-intensive and the analysis naturally required visual presentations of number-crunching results in a readable manner. One of the requirements was to present numeric results in a data table, so we naturally use <i><b>uitable</b></i> for this.<br />
Today I will show how using some not-so-complex Java we can transform the standard Matlab <i><b>uitable</b></i> into something much more useful.</p>
<h3 id="basic">First pass &#8211; basic data table</h3>
<p>We start by displaying the data in a simple <i><b>uitable</b></i>. The essence of the relevant code snippet was something like this:</p>
<pre lang='matlab'>
headers = {'Periods', ...
           '<html><center>Any period<br />returns</center></html>', ...
           '<html><center>Avg return<br />signal</center></html>', ...
           '<html><center>Avg<br />gain</center></html>', ...
           '<html><center>Avg<br />draw</center></html>', ...
           '<html><center>Gain/draw<br />ratio</center></html>', ...
           '<html><center>Max<br />gain</center></html>', ...
           '<html><center>Max<br />draw</center></html>', ...
           '<html><center>Random<br />% pos</center></html>', ...
           '<html><center>Signal<br />% pos</center></html>', ...
           'Payout', '% p-value'};
hTable = uitable('Data',data, 'ColumnEditable',false, ...
           'ColumnName',headers, 'RowName',[], ...
           'ColumnFormat',['numeric',repmat({'bank'},1,11)], ...
           'ColumnWidth','auto', ...
           'Units','norm', 'Position',[0,.75,1,.25]);
</pre>
<p><center><figure style="width: 596px" class="wp-caption aligncenter"><img decoding="async" alt="Plain data table - so boooooring..." src="https://undocumentedmatlab.com/images/uitable_plain1.png" title="Plain data table - so boooooring..." width="596" /><figcaption class="wp-caption-text">Plain data table - so boooooring...</figcaption></figure></center><br />
We can see from this simple example how I have used HTML to format the header labels into two rows, to enable compact columns. I have already <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">described</a> using HTML formatting in Matlab controls in several articles on this website. I have not done this here, but you can easily use HTML formatting for other effect such as superscript (&lt;sup&gt;), subscript (&lt;sub&gt;), bold (&lt;b&gt;), italic (&lt;i&gt;), font sizes and colors (&lt;font&gt;) and other standard HTML effects.<br />
Even with the multi-line headers, the default column width appears to be too wide. This is apparently an internal Matlab bug, not taking HTML into consideration. This causes only part of the information to be displayed on screen, and requires the user to either scroll right and left, or to manually resize the columns.</p>
<h3 id="auto-resizing">Second pass &#8211; auto-resizing that actually works&#8230;</h3>
<p>To solve the auto-resizing issue, we resort to a bit of Java magic powder. We start by using the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a> to get the table&#8217;s underlying Java reference handle. This is the containing scrollpane, and we are interested in the actual data table inside. We then use the <i>setAutoResizeMode</i>, as <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/JTable.html#setAutoResizeMode%28int%29">described</a> in the official Java documentation.</p>
<pre lang='matlab'>
jScroll = findjobj(hTable);
jTable = jScroll.getViewport.getView;
jTable.setAutoResizeMode(jTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
</pre>
<p><center><figure style="width: 596px" class="wp-caption aligncenter"><img decoding="async" alt="Auto-resized columns that actually work" src="https://undocumentedmatlab.com/images/uitable_plain2.png" title="Auto-resized columns that actually work" width="596" /><figcaption class="wp-caption-text">Auto-resized columns that actually work</figcaption></figure></center></p>
<h3 id="colors">Third pass &#8211; adding colors</h3>
<p>There are still quite a few other customizations needed here: enable <a target="_blank" href="/articles/uitable-sorting/">sorting</a>; remove the border outline; set a white background; set row (rather than cell) selection and several other fixes that may seem trivial by themselves but together giver a much more stylish look to the table&#8217;s look and feel. I&#8217;ll skip these for now (interested readers can read all about them, and more, in my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a>).<br />
One of the more important customizations is to add colors depending on the data. In my client&#8217;s case, there were three requirements:</p>
<ul>
<li>data that could be positive or negative should be colored in <b><font color="green">green</font></b> or <b><font color="red">red</font></b> foreground color respectively</li>
<li>large payouts (abs &gt; 2) should be colored in <b><font color="blue">blue</font></b></li>
<li>data rows that have statistical significance (%p-value &lt; 5) should have a <span style="background-color:#ffff00;">yellow background highlight</span></li>
</ul>
<p>While we could easily use HTML or CSS formatting to do this, this would be bad for performance in a large data table, may cause some issues when editing table cells or sorting columns. I chose to use the alternative method of <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer">cell renderers</a>.<br />
<code>ColoredFieldCellRenderer</code> is a simple table cell renderer that enables setting cell-specific foreground/background colors and tooltip messages (it also has a few other goodies like smart text alignment etc.). This requires some Java knowledge to program, but in this case you can simply <a href="/files/ColoredFieldCellRenderer.zip">download</a> the ColoredFieldCellRenderer.zip file and use it, even if you don&#8217;t know Java. The source code is included in the zip file, for anyone who is interested.<br />
After using <i><b>javaaddpath</b></i> to add the zip file to the dynamic Java classpath (you can add it to the static <i>classpath.txt</i> file instead), the contained Java class file is available for use in Matlab. We configure it according to our data and then assign it to all our table&#8217;s columns.<br />
Java savvy readers might complain that the data-processing should perhaps be done in the renderer class rather than in Matlab. I have kept it in Matlab because this would enable very easy modification of the highlighting algorithm, without any need to modify the generic Java renderer class.<br />
Unfortunately, in the new <i><b>uitable</b></i> design (the version available since R2008a), JIDE and Matlab have apparently broken the <a target="_blank" rel="nofollow" href="http://java.sun.com/products/jfc/tsc/articles/architecture">standard MVC approach</a> by using a table model that not only controls the data but also sets the table&#8217;s appearance (row-striping background colors, for example), and disregards column cell-renderers. In order for our custom cell renderer to have any effect, we must therefore replace Matlab&#8217;s standard <code>DefaultUIStyleTableModel</code> with a simple <code>DefaultTableModel</code>. This in itself is not enough – we also need to ensure that the <i><b>uitable</b></i> has an empty <strong>ColumnFormat</strong> property, because if it is non-empty then it overrides our cell-renderer.<br />
In the following code, note that Java row and column indices start at 0, not at 1 like in Matlab. We need to be careful about indices when programming java in Matlab.<br />
The rest of the code should be pretty much self explanatory (again &#8211; more details can be found in the above-mentioned report):</p>
<pre lang='matlab'>
% Initialize our custom cell renderer class object
javaaddpath('ColoredFieldCellRenderer.zip');
cr = ColoredFieldCellRenderer(java.awt.Color.white);
cr.setDisabled(true);  % to bg-color the entire column
% Set specific cell colors (background and/or foreground)
for rowIdx = 1 : size(data,1)
  % Red/greed foreground color for the numeric data
  for colIdx = 2 : 8
    if data(rowIdx,colIdx) < 0
      cr.setCellFgColor(rowIdx-1,colIdx-1,java.awt.Color(1,0,0));    % red
    elseif data(rowIdx,colIdx) > 0
      cr.setCellFgColor(rowIdx-1,colIdx-1,java.awt.Color(0,0.5,0));  % green
    end
  end
  % Yellow background for significant rows based on p-value
  if data(rowIdx,12) < = 5 &#038;&#038; data(rowIdx,11)~=0
    for colIdx = 1 : length(headers)
      cr.setCellBgColor(rowIdx-1,colIdx-1,java.awt.Color(1,1,0));    % yellow
    end
  end
  % Bold blue foreground for significant payouts
  if abs(data(rowIdx,11)) >= 2
    cr.setCellFgColor(rowIdx-1,10,java.awt.Color(0,0,1));    % blue
    % Note: the following could easily be done in the renderer, just like the colors
    boldPayoutStr = ['<html><b>' num2str(data(rowIdx,11),'%.2f') '</b></html>'];
    %jTable.setValueAt(boldPayoutStr,rowIdx-1,10);  % this is no good: overridden when table model is replaced below...
    dataCells{rowIdx,11} = boldPayoutStr;
  end
end
% Replace Matlab's table model with something more renderer-friendly...
jTable.setModel(javax.swing.table.DefaultTableModel(dataCells,headers));
set(hTable,'ColumnFormat',[]);
% Finally assign the renderer object to all the table columns
for colIdx = 1 : length(headers)
  jTable.getColumnModel.getColumn(colIdx-1).setCellRenderer(cr);
end
</pre>
<p><center><figure style="width: 590px" class="wp-caption aligncenter"><img decoding="async" alt="Finally something lively!" src="https://undocumentedmatlab.com/images/uitable_colored.png" title="Finally something lively!" width="590" /><figcaption class="wp-caption-text">Finally something lively!</figcaption></figure></center><br />
This may not take a beauty contest prize, but you must admit that it now looks more useful than the original table at the top of this article.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-cell-colors">Uitable cell colors</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitab-colors-icons-images" rel="bookmark" title="Uitab colors, icons and images">Uitab colors, icons and images </a> <small>Matlab's semi-documented tab panels can be customized using some undocumented hacks...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitable-cell-colors/feed</wfw:commentRss>
			<slash:comments>124</slash:comments>
		
		
			</item>
		<item>
		<title>Tri-state checkbox</title>
		<link>https://undocumentedmatlab.com/articles/tri-state-checkbox?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tri-state-checkbox</link>
					<comments>https://undocumentedmatlab.com/articles/tri-state-checkbox#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 19 Oct 2011 14:04:20 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2467</guid>

					<description><![CDATA[<p>Matlab checkboxes can easily be made to support tri-state functionality.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/tri-state-checkbox">Tri-state checkbox</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage" rel="bookmark" title="Unorthodox checkbox usage">Unorthodox checkbox usage </a> <small>There are various ways to display interactive split-panes in Matlab GUI. Uiextras flex-panels override a checkbox control's CData to display a divider. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/determining-axes-zoom-state" rel="bookmark" title="Determining axes zoom state">Determining axes zoom state </a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/recovering-previous-editor-state" rel="bookmark" title="Recovering previous editor state">Recovering previous editor state </a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>When presenting information visually in graphical user interfaces (GUIs), we often need to present and enable interaction with state data (such as On/Off). In most cases, we would naturally use a checkbox to present the information and enable interaction. But What can we do if the data has three possible states. For example, Yes/No/Maybe, or: Full/Empty/Partial, or: Up/Down/Undetermined ?<br />
Until today, Matlab GUIs had to resort to using drop-down (aka combo-box or popup-menu) or radio-button controls to present such information. However, would it not be nicer if we could still use a checkbox? Outside Matlab, such a control is known as a tri-state checkbox and many modern GUI frameworks support it. Well, surprise surprise, so does Matlab (although you would never guess it from the documentation).</p>
<h3 id="CheckBoxTree">CheckBoxTree</h3>
<p>Last year, I have already <a target="_blank" href="/articles/customizing-uitree-nodes-2/#Built-in-classes">described</a> a built-in Matlab tree control whose nodes have tri-state checkboxes:<br />
<center><figure style="width: 311px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="a regular MJTree (left) and a CheckBoxTree (right)" src="https://undocumentedmatlab.com/images/CheckBoxTree.png" title="a regular MJTree (left) and a CheckBoxTree (right)" width="311" height="218" /><figcaption class="wp-caption-text">a regular MJTree (left) and a CheckBoxTree (right)</figcaption></figure></center><br />
Today I will show how we can use these checkboxes as independent GUI controls.</p>
<h3 id="uicontrol">Modifying the standard Matlab checkbox uicontrol</h3>
<p>In order to modify the standard Matlab checkbox <i><b>uicontrol</b></i>, we need to first get its underlying Java component reference. This is done using the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a>. We then update its UI wrapper to be the same as the <code>CheckBoxTree</code>&#8216;s checkbox control.<br />
To programmatically set a mixed state we update the &#8216;selectionState&#8217; client property to <code>SelectionState.MIXED</code> (<code>SelectionState</code> also has the <code>SELECTED</code> and <code>NOT_SELECTED</code> values).<br />
Here is an end-to-end example:</p>
<pre lang='matlab'>
hCB = uicontrol('Style','checkbox', ...);
jCB = findjobj(hCB);
jCB.setUI(com.mathworks.mwswing.checkboxtree.TriStateButtonUI(jCB.getUI));
% Update the checkbox state to MIXED
newState = com.mathworks.mwswing.checkboxtree.SelectionState.MIXED;
jCB.putClientProperty('selectionState', newState);
jCB.repaint;
</pre>
<p><center><figure style="width: 289px" class="wp-caption aligncenter"><img decoding="async" alt="Matlab checkboxes displaying mixed states" src="https://undocumentedmatlab.com/images/CheckBox_TriState.png" title="Matlab checkboxes displaying mixed states" width="289" /><figcaption class="wp-caption-text">Matlab checkboxes displaying mixed states</figcaption></figure></center></p>
<h3 id="independent">Displaying as an independent Java control</h3>
<p>Instead of retrofitting a standard Matlab <i><b>uicontrol</b></i> as described above, we can directly use the standard <code>javax.swing.JCheckBox</code> which does not normally support tri-state (it only has two states), displaying it in our GUI with the built-in <a target="_blank" href="/articles/javacomponent/"><i><b>javacomponent</b></i> function</a>:</p>
<pre lang='matlab'>
% Display the checkbox (UNSELECTED state at first)
jCB = javax.swing.JCheckBox('JCheckBox - mixed',0);
javacomponent(jCB, [10,70,150,20], gcf);
% Update the checkbox state to MIXED
import com.mathworks.mwswing.checkboxtree.*
jCB.setUI(TriStateButtonUI(jCB.getUI));
jCB.putClientProperty('selectionState', SelectionState.MIXED);
jCB.repaint;
</pre>
<p>Note that instead of using <code>javax.swing.JCheckBox</code>, we could use the internal Matlab class <code>com.mathworks.mwswing.MJCheckBox</code>, which directly extends <code>JCheckBox</code> and adds mnemonic (shortcut-key) support, but is otherwise fully compatible with <code>JCheckBox</code>. Actually, it is <code>MJCheckBox</code> which is the underlying Java component of the standard Matlab checkbox <i><b>uicontrol</b></i>.</p>
<h3 id="alternatives">Alternative controls</h3>
<p>Now that we have seen that Matlab includes built-in support (well, at least support in the technical sense, not the official customer-support sense), would you be surprised to learn that it includes similar support in other internal components as well?<br />
The internal Matlab class <code>com.mathworks.mwt.MWCheckbox</code> directly supports a tri-state (yes/no/maybe) checkbox, without any need to update its UI, as follows:</p>
<pre lang='matlab'>
% Display the checkbox (UNSELECTED state at first)
jCB = com.mathworks.mwt.MWCheckbox('MWCheckbox - mixed',0);
javacomponent(jCB, [10,70,150,20], gcf);
% Update the checkbox state to MIXED
jCB.setMixedState(true);
% Retrieve the current state
isMixedFlag = jCB.isMixedState();  % true/false
</pre>
<p><center><figure style="width: 289px" class="wp-caption aligncenter"><img decoding="async" alt="MJCheckBox vs. MWCheckbox" src="https://undocumentedmatlab.com/images/CheckBox_MWT_MWSwing.png" title="MJCheckBox vs. MWCheckbox" width="289" /><figcaption class="wp-caption-text">MJCheckBox vs. MWCheckbox</figcaption></figure></center><br />
Note that the State property, which controls the standard selected/unselected state, is entirely independent from the MixedState property. Both State and MixedState are boolean properties, so to get the actual checkbox state we need to query both of these properties.<br />
Another internal Matlab class that we can use is JIDE&#8217;s <code>com.jidesoft.swing.TristateCheckBox</code> (which is pre-bundled in Matlab and is fully documented <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/TristateCheckBox.html">here</a>).<br />
There are many other tri-state checkbox alternatives available online (for example, <a target="_blank" rel="nofollow" href="https://forums.oracle.com/forums/search.jspa?threadID=&#038;q=%28tri-state+OR+tristate%29+AND+checkbox&#038;objID=c285&#038;dateRange=all&#038;userID=&#038;numResults=30&#038;rankBy=10001">here</a>, <a target="_blank" rel="nofollow" href="http://www.javaspecialists.eu/archive/Issue145.html">here</a> and <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/1263323/tristate-checkboxes-in-java">here</a>). We can easily include them in our Matlab GUI with the <i><b>javacomponent</b></i> function. Using external components we can be more certain of the compatibility issues in past and future Matlab releases. On the other hand, internal Matlab classes do have the advantage of being inherently accessible on all platforms of the same Matlab release, whereas non-Matlab components must be included in our deployment package.<br />
Do you use any tri-state controls, either Matlab or external, in your work? If so, please share your experience in a <a href="/articles/tri-state-checkbox/#respond">comment below</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/tri-state-checkbox">Tri-state checkbox</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage" rel="bookmark" title="Unorthodox checkbox usage">Unorthodox checkbox usage </a> <small>There are various ways to display interactive split-panes in Matlab GUI. Uiextras flex-panels override a checkbox control's CData to display a divider. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/determining-axes-zoom-state" rel="bookmark" title="Determining axes zoom state">Determining axes zoom state </a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/recovering-previous-editor-state" rel="bookmark" title="Recovering previous editor state">Recovering previous editor state </a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/tri-state-checkbox/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
