<?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>HTML &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/html/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Tue, 11 Apr 2023 09:40:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>
	<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>Sending HTML emails from Matlab</title>
		<link>https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sending-html-emails-from-matlab</link>
					<comments>https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 Aug 2017 21:19:42 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internal component]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6986</guid>

					<description><![CDATA[<p>Matlab's sendmail only sends simple text messages by default; a simple hack can cause it to send HTML-formatted messages. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab">Sending HTML emails from Matlab</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/sending-email-text-messages-from-matlab" rel="bookmark" title="Sending email/text messages from Matlab">Sending email/text messages from Matlab </a> <small>Sending emails and SMS (text) messages from Matlab is easy, once you know a few quirks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-formatting-using-html" rel="bookmark" title="GUI formatting using HTML">GUI formatting using HTML </a> <small>HTML formatting an be used to align and background-color text within Matlab uicontrols such as buttons, listboxes, uitables etc. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few months ago I wrote about various tricks for <a href="/articles/sending-email-text-messages-from-matlab" target="_blank">sending email/text messages from Matlab</a>. Unfortunately, Matlab only sends text emails by default and provides no documented way to send HTML-formatted emails. Text-only emails are naturally very bland and all mail clients in the past 2 decades support HTML-formatted emails. Today I will show how we can send such HTML emails from Matlab.<br />
A quick recap: Matlab&#8217;s <i><b>sendmail</b></i> function uses Java (specifically, the standard <code>javax.mail</code> package) to prepare and send emails. The Java classes are extremely powerful and so there is no wonder that Mathworks chose to use them rather than reinventing the wheel. However, Matlab&#8217;s <i><b>sendmail</b></i> function only uses part of the functionality exposed by these classes (admittedly, the most important parts that deal with the basic mail-sending mechanism), and does not expose external hooks or input args that would enable the user to take full advantage of the more advanced features, HTML formatting included.<br />
Only two small changes are needed in <i>sendmail.m</i> to support HTML formatting:</p>
<ol>
<li>HTML formatting required calling the message-object&#8217;s <i>setContent()</i> method, rather than <i>setText()</i>.</li>
<li>We need to specify <code>'text/html'</code> as part of the message&#8217;s encoding</li>
</ol>
<p><span id="more-6986"></span><br />
To implement these features, change the following (lines #119-130 in the original <i>sendmail.m</i> file of R2017a, changed lines highlighted):</p>
<pre lang="matlab" highlight="3-4,12">
% Construct the body of the message and attachments.
body = formatText(theMessage);
if numel(attachments) == 0
    if ~isempty(charset)
        msg.setText(body, charset);
    else
        msg.setText(body);
    end
else
    % Add body text.
    messageBodyPart = MimeBodyPart;
    if ~isempty(charset)
        messageBodyPart.setText(body, charset);
    ...
</pre>
<p>to this (changed lines highlighted):</p>
<pre lang="matlab" highlight="3-14,22-24">
% Construct the body of the message and attachments.
body = formatText(theMessage);
isHtml = ~isempty(body) && body(1) == '<';  % msg starting with '<' indicates HTML
if isHtml
    if isempty(charset)
        charset = 'text/html; charset=utf-8';
    else
        charset = ['text/html; charset=' charset];
    end
end
if numel(attachments) == 0  &#038;&#038; ~isHtml
    if isHtml
        msg.setContent(body, charset);
    elseif ~isempty(charset)
        msg.setText(body, charset);
    else
        msg.setText(body);
    end
    else
        % Add body text.
        messageBodyPart = MimeBodyPart;
        if isHtml
            messageBodyPart.setContent(body, charset);
        elseif ~isempty(charset)
            messageBodyPart.setText(body, charset);
        ...
</pre>
<p>In addition, I also found it useful to remove the hard-coded 75-character line-wrapping in text messages. This can be done by changing the following (line #291 in the original <i>sendmail.m</i> file of R2017a):</p>
<pre lang="matlab">maxLineLength = 75;</pre>
<p>to this:</p>
<pre lang="matlab">maxLineLength = inf;  % or some other large numeric value</pre>
<h3 id="deployment">Deployment</h3>
<p>It's useful to note two alternatives for making these fixes:</p>
<ul>
<li>Making the changes directly in <i>%matlabroot%/toolbox/matlab/iofun/sendmail.m</i>. You will need administrator rights to edit this file. You will also need to redo the fix whenever you install Matlab, either installation on a different machine, or installing a new Matlab release. In general, I discourage changing Matlab's internal files because it is simply not very maintainable.</li>
<li>Copying <i>%matlabroot%/toolbox/matlab/iofun/sendmail.m</i> into a dedicated wrapper function (e.g., <i>sendEmail.m</i>) that has a similar function signature and exists on the Matlab path. This has the benefit of working on multiple Matlab releases, and being copied along with the rest of our m-files when we install our Matlab program on a different computer. The downside is that our wrapper function will be stuck with the version of <i>sendmail.m</i> that we copied into it, and we'd lose any possible improvements that Mathworks may implement in future Matlab releases.</li>
</ul>
<p>The basic idea for the second alternative, the <i>sendEmail.m</i> wrapper, is something like this (the top highlighted lines are the additions made to the original <i>sendmail.m</i>, with everything placed in <i>sendEmail.m</i> on the Matlab path):<br />
<!--more--></p>
<pre lang="matlab" highlight="1-3">
function sendEmail(to,subject,theMessage,attachments)
%SENDEMAIL Send e-mail wrapper (with HTML formatting)
   sendmail(to,subject,theMessage,attachments);
% The rest of this file is copied from %matlabroot%/toolbox/matlab/iofun/sendmail.m (with the modifications mentioned above):
function sendmail(to,subject,theMessage,attachments)
%SENDMAIL Send e-mail.
%   SENDMAIL(TO,SUBJECT,MESSAGE,ATTACHMENTS) sends an e-mail.  TO is either a
%   character vector specifying a single address, or a cell array of character vector
...
</pre>
<p>We would then call the wrapper function as follows:</p>
<pre lang="matlab">
sendEmail('abc@gmail.com', 'email subject', 'regular text message');     % will send a regular text message
sendEmail('abc@gmail.com', 'email subject', '<b><font color="blue">HTML-formatted</font> <i>message');  % HTML-formatted message
</pre>
<p>In this case, the code automatically infers HTML formatting based on whether the first character in the message body is a '&lt;' character. Instead, we could just as easily have passed an additional input argument (<code>isHtml</code>) to our <i>sendEmail</i> wrapper function.<br />
Hopefully, in some future Matlab release Mathworks will be kind enough to enable sending 21<sup>st</sup>-century HTML-formatted emails without needing such hacks. Until then, note that <i>sendmail.m</i> relies on standard non-GUI Java networking classes, which are expected to be supported far into the future, well after Java-based GUI may cease to be supported in Matlab. For this reason I believe that while it seems a bit tricky, the changes that I outlined in today's post actually have a <a href="/articles/category/presumed-future-risk/low-risk-of-breaking-in-future-versions" target="_blank">low risk of breaking in a future Matlab release</a>.<br />
Do you have some other advanced email feature that you use in your Matlab program by some crafty customization to <i><b>sendmail</b></i>? If so, please share it in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab">Sending HTML emails from Matlab</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/sending-email-text-messages-from-matlab" rel="bookmark" title="Sending email/text messages from Matlab">Sending email/text messages from Matlab </a> <small>Sending emails and SMS (text) messages from Matlab is easy, once you know a few quirks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-formatting-using-html" rel="bookmark" title="GUI formatting using HTML">GUI formatting using HTML </a> <small>HTML formatting an be used to align and background-color text within Matlab uicontrols such as buttons, listboxes, uitables etc. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>GUI formatting using HTML</title>
		<link>https://undocumentedmatlab.com/articles/gui-formatting-using-html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gui-formatting-using-html</link>
					<comments>https://undocumentedmatlab.com/articles/gui-formatting-using-html#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 05 Apr 2017 20:26:44 +0000</pubDate>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6877</guid>

					<description><![CDATA[<p>HTML formatting an be used to align and background-color text  within Matlab uicontrols such as buttons, listboxes, uitables etc. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/gui-formatting-using-html">GUI formatting using HTML</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/sending-html-emails-from-matlab" rel="bookmark" title="Sending HTML emails from Matlab">Sending HTML emails from Matlab </a> <small>Matlab's sendmail only sends simple text messages by default; a simple hack can cause it to send HTML-formatted messages. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/formatting-numbers" rel="bookmark" title="Formatting numbers">Formatting numbers </a> <small>Number formatting is easy to achieve in Matlab, by using a dedicated built-in Java object....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>As I&#8217;ve mentioned several times in the past, <a href="/articles/html-support-in-matlab-uicomponents" target="_blank">HTML can be used for simple formatting of GUI controls</a>, including font colors/sizes/faces/angles. With a bit of thought, HTML (and some CSS) can also be used for non-trivial formatting, that would otherwise require the <a href="/articles/button-customization" target="_blank">use of Java</a>, such as text alignment, background color, and using a combination of text and icons in the GUI control&#8217;s contents.</p>
<h3 id="Alignment">Alignment</h3>
<p>For example, a question that I am often asked (<a href="/articles/html-support-in-matlab-uicomponents#comment-403579" target="_blank">latest example</a>) is whether it is possible to left/center/right align the label within a Matlab button, listbox or table. While Matlab does not (yet) have properties that control alignment in uicontrols, we can indeed use HTML for this. There&#8217;s a catch though: if we simply tried to use <code>&lt;div align="left"&gt;</code>&#8230;, it will not work. No error will be generated but we will not see any visible left-alignment. The reason is that internally, the text is contained within a snugly-fitting box. Aligning anything within a tight-fitting box obviously has no effect.<br />
To solve the problem, we need to tell Matlab (or rather, the HTML interpreter used by the underlying Java control) to widen this internal box. One way to do this is to specify the width of the <code>div</code> tag, which can be enormous in order to span the entire available apace (<code>&lt;div width="999px" align="left"&gt;</code>&#8230;). Another method is to simulate a simple HTML table that contains a single cell that holds the text, and then tell HTML the table cell&#8217;s width:</p>
<pre lang="matlab">
hButton.String   = '<html><tr><td width=9999 align=left>Left-aligned';  % left-align within a button
hTable.Data{2,1} = '<html><tr><td width=9999 align=right>And right';   % right-align within a specific uitable cell
</pre>
<p><center><figure style="width: 140px" class="wp-caption aligncenter"><img decoding="async" alt="centered (default) button label" src="https://undocumentedmatlab.com/images/button-center-align.gif" title="centered (default) button label" width="60" height="20" /> &nbsp; <img loading="lazy" decoding="async" alt="right-aligned button label" src="https://undocumentedmatlab.com/images/button-right-align.gif" title="right-aligned button label" width="60" height="20" /><figcaption class="wp-caption-text">Centered (default) and right-aligned button labels</figcaption></figure></center><br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Non-default alignment of uitable cells" src="https://undocumentedmatlab.com/images/uitable-cell-align.gif" title="Non-default alignment of uitable cells" width="200" height="40" /><figcaption class="wp-caption-text">Non-default alignment of uitable cells</figcaption></figure></center><br />
I discussed the specific aspect of uicontrol content alignment in <a href="/articles/aligning-uicontrol-contents" target="_blank">another post</a> last year.</p>
<h3 id="bgcolor">Background color</h3>
<p>The same problem (and solution) applies to background colors: if we don&#8217;t enlarge the snugly-fitting internal bounding-box, any HTML bgcolor that we specify would only be shown under the text (i.e., within the internal box&#8217;s confines). In order to display bgcolor across the entire control/cell width, we need to enlarge the internal box&#8217;s width (the <code>align</code> and <code>bgcolor</code> tags can of course be used together):<br />
<span id="more-6877"></span></p>
<pre lang="matlab">
hButton.String   = '<html><tr><td width=9999 bgcolor=#ffff00>Yellow';  % bgcolor within a button
hTable.Data{2,1} = '<html><tr><td width=9999 bgcolor=#ffff00>Yellow';  % bgcolor within a specific uitable cell
</pre>
<h3 id="CSS">CSS</h3>
<p>We can also use simple CSS, which provides more formatting customizability than plain HTML:</p>
<pre lang="matlab">
hTable.Data{2,1} = '<html><tr><td width=9999 style="background-color:yellow">Yellow';
</pre>
<p>HTML/CSS formatting is a poor-man&#8217;s hack. It is very crude compared to the numerous customization options available via Java. However, it does provide a reasonable solution for many use-cases, without requiring any Java. I discussed the two approaches for uitable cell formatting <a href="/articles/uitable-cell-colors" target="_blank">in this post</a>.</p>
<h3 id="uifigures">[Non-]support in uifigures</h3>
<p><b><u>Important note</u></b>: HTML formatting  is <b>NOT</b> [yet] supported by the new web-based uifigures. While uifigures can indeed be hacked with HTML/CSS content (<a href="/articles/uitable-cell-colors" target="_blank">details</a>), this is not an easy task. Since it should be trivially easy for MathWorks to enable HTML content in the new web-based uifigures, I implore anyone who uses HTML in their Matlab GUI to let MathWorks know about it so that they could prioritize this R&#038;D effort into an upcoming Matlab release. You can send an email to Eric.Sargent at mathworks.com, who apparently handles such aspects in MathWorks&#8217; R&#038;D efforts to transition from Java-based GUIs to web-based ones. In my previous post I spotlit MathWorks <a href="/articles/mathworks-solicited-java-survey" target="_blank">user-feedback surveys</a> about users&#8217; use of Java GUI aspects, aimed in order to migrate as many of the use-cases as possible onto the new web-based framework. HTML/CSS support is a natural by-product of the fact that Matlab&#8217;s non-web-based GUI is based on Java Swing components (that inherently support HTML/CSS). But unfortunately the MathWorks surveys are specific to the <i><b>javacomponent</b></i> function and the figure&#8217;s <b>JavaFrame</b> property. In other words, many users might be using undocumented Java aspects by simply using HTML content in their GUI, without ever realizing it or using <i><b>javacomponent</b></i>. So I think that in this case a simple email to Eric.Sargent at mathworks.com to let him know how you&#8217;re using HTML would be more useful. Maybe one day MathWorks will be kind enough to post a similar survey specific to HTML support, or maybe one day they&#8217;s just add the missing HTML support, if only to be done with my endless nagging. 🙂<br />
p.s. &#8211; I am well aware that we can align and bgcolor buttons in AppDesigner. But we can&#8217;t do this with individual table/listbox cells, and in general we can&#8217;t use HTML within uifigures without extensive hacks. I merely used the simple examples of button and uitable cell formatting in today&#8217;s post to illustrate the issue. So please don&#8217;t get hung up on the specifics, but rather on the broader issue of HTML support in uifigures.<br />
And in the meantime, for as long as non-web-based GUI is still supported in Matlab, keep on enjoying the benefits that HTML/CSS provides.</p>
<h3 id="email">Automated bug-fix emails</h3>
<p>In an unrelated matter, I wish to express my Kudos to the nameless MathWorkers behind the scenes who, bit by bit, improve Matlab and the user experience: Over the years I&#8217;ve posted a few times <a href="/articles/couple-of-matlab-bugs-and-workarounds" target="_blank">my frustrations</a> with the opaqueness of MathWorks&#8217; bug-reporting mechanism. One of my complaints was that users who file bugs are not notified when a fix or workaround becomes available. That at least seems to have been fixed now. I just received a seemingly-automated email notifying me that one of the bugs that I reported a few years ago has been fixed. This is certainly a good step in the right direction, so thank you!<br />
Happy Passover/Easter to all!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/gui-formatting-using-html">GUI formatting using HTML</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/sending-html-emails-from-matlab" rel="bookmark" title="Sending HTML emails from Matlab">Sending HTML emails from Matlab </a> <small>Matlab's sendmail only sends simple text messages by default; a simple hack can cause it to send HTML-formatted messages. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/formatting-numbers" rel="bookmark" title="Formatting numbers">Formatting numbers </a> <small>Number formatting is easy to achieve in Matlab, by using a dedicated built-in Java object....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/gui-formatting-using-html/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Icon images &#038; text in Matlab uicontrols</title>
		<link>https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=icon-images-in-matlab-uicontrols</link>
					<comments>https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 28 Sep 2016 10:28:04 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6687</guid>

					<description><![CDATA[<p>HTML can be used to add image icons to Matlab listbox and popup (drop-down) controls. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols">Icon images &amp; text in Matlab uicontrols</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/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/animated-busy-spinning-icon" rel="bookmark" title="Animated busy (spinning) icon">Animated busy (spinning) icon </a> <small>An animated spinning icon label can easily be embedded in Matlab GUI. ...</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>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>One of my consulting clients recently asked me if I knew any builtin Matlab GUI control that could display a list of <a href="http://www.mathworks.com/help/matlab/ref/colormap.html#inputarg_name" rel="nofollow" target="_blank">colormap names</a> alongside their respective image icons, in a listbox or popup menu (drop-down/combo-box):<br />
<center><figure style="width: 520px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab listbox with icon images" src="https://undocumentedmatlab.com/images/html_listbox.png" title="Matlab listbox with icon images" width="270" height="200" /> &nbsp; <img loading="lazy" decoding="async" alt="Matlab popup menu (dropdown/combobox) with icon images" src="https://undocumentedmatlab.com/images/html_popup.png" title="Matlab popup menu (dropdown/combobox) with icon images" width="224" height="264" /><figcaption class="wp-caption-text">Matlab listbox (left) & popup menu (right) with icon images</figcaption></figure></center><br />
My initial thought was that this should surely be possible, since <b>Colormap</b> is a documented figure property, that should therefore be listed inside the <a href="http://www.mathworks.com/help/matlab/ref/inspect.html" rel="nofollow" target="_blank">inspector window</a>, and should therefore have an associated builtin Java control for the dropdown (just like other inspector controls, which are part of the <code>com.mathworks.mlwidgets</code> package, or possibly as a standalone control in the <code>com.mathworks.mwswing</code> package). To my surprise it turns out that for some unknown reason MathWorks neglected to add the <b>Colormap</b> property (and associated Java controls) to the inspector. This property is fully documented and all, just like <b>Color</b> and other standard figure properties, but unlike them <b>Colormap</b> can only be modified programmatically, not via the inspector window. Matlab does provide the related <i><b>colormapeditor</b></i> function and associated dialog window, but I would have expected a simple drop-down of the standard builtin colormaps to be available in the inspector. Anyway, this turned out to be a dead-end.<br />
It turns out that we can relatively easily implement the requested listbox/combo-box using a bit of HTML magic, <a href="/articles/aligning-uicontrol-contents" target="_blank">as I explained</a> last week. The basic idea is for each of the listbox/combobox items to be an HTML string that contains both an &lt;img&gt; tag for the icon and the item label text. For example, such a string might contain something like this (parula is Matlab&#8217;s default colormap in HG2, starting in R2014b):</p>
<pre lang="xml"><html><img decoding="async" src="http://www.mathworks.com/help/matlab/ref/colormap_parula.png">parula</pre>
<p><center><figure style="width: 434px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="parula colormap image" src="http://www.mathworks.com/help/matlab/ref/colormap_parula.png" title="parula colormap image" width="434" height="27" /><figcaption class="wp-caption-text">parula colormap image</figcaption></figure></center><br />
<span id="more-6687"></span>Of course, it would be a bit inefficient for each of the icons to be fetched from the internet. Luckily, the full set of Matlab documentation is typically installed on the local computer as part of the standard Matlab installation, beneath the <i><b>docroot</b></i> folder (e.g., <i>C:\Program Files\Matlab\R2016b\help</i>). In our specific case, the parula colormap image is located in:</p>
<pre lang="matlab">imageFilename = [docroot, '/matlab/ref/colormap_parula.png']</pre>
<p>Note that for a local image to be accepted by HTML, it needs to follow certain conventions. In our case, the HTML string for displaying the above image is:</p>
<pre lang="xml"><html><img decoding="async" src="file:///C:/Program%20Files/Matlab/R2016b/help/matlab/ref/colormap_parula.png">parula</pre>
<blockquote><p><u>Warning</u>: it&#8217;s easy when dealing with HTML images in Matlab to get the format confused, resulting in a red-x icon. I <a href="/articles/images-in-matlab-uicontrols-and-labels" target="_blank">discussed this issue</a> some 4 years ago, which is still relevant.</p></blockquote>
<p>How can we get the list of available builtin colormaps? The standard Matlab way of doing this would be something like this:</p>
<pre lang="matlab">
>> possibleColormaps = set(gcf,'Colormap')
possibleColormaps =
     {}
</pre>
<p>but as we can see, for some unknown reason (probably another MathWorks omission), Matlab does not list the names of its available builtin colormaps.<br />
Fortunately, all the builtin colormaps have image filenames that follow the same convention, which make it easy to get this list by simply listing the names of the relevant files, from which we can easily create the necessary HTML strings:</p>
<pre lang="matlab">
>> iconFiles = dir([docroot, '/matlab/ref/colormap_*.png']);
>> colormapNames = regexprep({iconFiles.name}, '.*_(.*).png', '$1')
colormapNames =
  Columns 1 through 9
    'autumn'    'bone'    'colorcube'    'cool'    'copper'    'flag'    'gray'    'hot'    'hsv'
  Columns 10 through 18
    'jet'    'lines'    'parula'    'pink'    'prism'    'spring'    'summer'    'white'    'winter'
>> htmlStrings = strcat('<html><img decoding="async" width=200 height=10 src="file:///C:/Program%20Files/Matlab/R2016a/help/matlab/ref/colormap_', colormapNames', '.png">', colormapNames')
str =
    '<html><img decoding="async" width=200 height=10 src="file:///C:/Program%20Files/Matlab/R2016a/help/matlab/ref/colormap_autumn.png">autumn'
    '<html><img decoding="async" width=200 height=10 src="file:///C:/Program%20Files/Matlab/R2016a/help/matlab/ref/colormap_bone.png">bone'
    '<html><img decoding="async" width=200 height=10 src="file:///C:/Program%20Files/Matlab/R2016a/help/matlab/ref/colormap_colorcube.png">colorcube'
    ...
>> hListbox = uicontrol(gcf, 'Style','listbox', 'Units','pixel', 'Pos',[10,10,270,200], 'String',htmlStrings);
>> hPopup   = uicontrol(gcf, 'Style','popup',   'Units','pixel', 'Pos',[10,500,270,20], 'String',htmlStrings);
</pre>
<p>&#8230;which results in the screenshots at the top of this post.<br />
Note how I scaled the images to 10px high (so that the labels would be shown and not cropped vertically) and 200px wide (so that it becomes narrower than the default 434px). There&#8217;s really no need in this case for the full 434&#215;27 image size &#8211; such flat images scale very nicely, even when their aspect ratio is not preserved. You can adjust the <code>height</code> and <code>width</code> values for a best fit with you GUI.<br />
Unfortunately, it seems that HTML strings are not supported in the new web-based uifigure controls. This is not really Matlab&#8217;s fault because the way to customize labels in HTML controls is via CSS: directly embedding HTML code in labels does not work (it&#8217;s a Java-Swing feature, not a browser feature). I really hope that either HTML or CSS processing will be enabled for web-based uicontrol in a future Matlab release, because until that time uifigure uicontrols will remain seriously deficient compared to standard figure uicontrols. Until then, if we must use uifigures and wish to customize our labels or listbox items, we can directly access the underlying web controls, <a href="/articles/customizing-uifigures-part-2" rel="nofollow" target="_blank">as Iliya explained here</a>.<br />
<span id="rant"></span><br />
A blog reader <a href="/articles/using-pure-java-gui-in-deployed-matlab-apps#comment-389045" target="_blank">recently complained</a> that I&#8217;m abusing Swing and basically making Matlab work in unnatural ways, &#8220;<i>something it was never meant to be</i>&#8220;. I feel that using HTML as I&#8217;ve shown last week and in this post would fall under the same category in his eyes. To him and to others who complain I say that I have absolutely no remorse about doing this. When I purchase anything I have the full rights (within the scope of the license) to adapt it in whatever way fits my needs. As a software developer and manager for over 25 years, I&#8217;ve developed in dozens of programming languages and environments, and I still enjoy [ab]using Matlab. Matlab is a great environment to get things done quickly and if this sometimes requires a bit of HTML or Java hacks that make some people cringe, then that&#8217;s their problem, not mine &#8211; I&#8217;m content with being able to do in Matlab [nearly] everything I want, quickly, and move on to the next project. As long as it gets the job done, that&#8217;s fine by me. If this makes me more of an engineer than a computer scientist, then so be it.<br />
On the flip side, I say to those who claim that Matlab is lacking in this or that aspect, that in most likelihood the limitation is only in their minds, not in Matlab &#8211; we can do amazing stuff with Matlab if we just open our minds, and possibly use some undocumented hacks. I&#8217;m not saying that Matlab has no limitations, I&#8217;m just saying that in most cases they can be overcome if we took the time and trouble to look for a solution. Matlab is a great tool and yet many people are not aware of its potential. Blaming Matlab for its failings is just an easy excuse in many cases. Of course, MathWorks could help my crusade on this subject by enabling useful features such as easy GUI component customizations&#8230;<br />
On this sad day, I wish you all <i>Shanah Tova!</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols">Icon images &amp; text in Matlab uicontrols</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/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/animated-busy-spinning-icon" rel="bookmark" title="Animated busy (spinning) icon">Animated busy (spinning) icon </a> <small>An animated spinning icon label can easily be embedded in Matlab GUI. ...</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>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Aligning uicontrol contents</title>
		<link>https://undocumentedmatlab.com/articles/aligning-uicontrol-contents?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aligning-uicontrol-contents</link>
					<comments>https://undocumentedmatlab.com/articles/aligning-uicontrol-contents#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 22 Sep 2016 13:10:18 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6663</guid>

					<description><![CDATA[<p>Matlab uicontrols can often be customized using plain HTML/CSS, without need for advanced Java. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/aligning-uicontrol-contents">Aligning uicontrol contents</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/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/spicing-up-matlab-uicontrol-tooltips" rel="bookmark" title="Spicing up Matlab uicontrol tooltips">Spicing up Matlab uicontrol tooltips </a> <small>Matlab uicontrol tooltips can be spiced-up using HTML and CSS, including fonts, colors, tables and images...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Matlab automatically aligns the text contents of uicontrols: button labels are centered, listbox contents are left-aligned, and table cells align depending on their contents (left-aligned for strings, centered for logical values, and right-aligned for numbers). Unfortunately, the control&#8217;s <b>HorizontalAlignment</b> property is generally ignored by uicontrols. So how can we force Matlab buttons (for example) to have right-aligned labels, or for listbox/table cells to be centered? Undocumented Matlab has the answer, yet again&#8230;<br />
It turns out that there are at least two distinct ways to set uicontrol alignment, using HTML and <a href="/articles/button-customization" rel="nofollow" target="_blank">using Java</a>. Today I will only discuss the HTML variant.<br />
The HTML method relies on the fact that <a href="/articles/html-support-in-matlab-uicomponents" target="_blank">Matlab uicontrols accept and process HTML strings</a>. This was true ever since Matlab GUI started relying on Java Swing components (which inherently <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/html.html" rel="nofollow" target="_blank">accept HTML labels</a>) over a decade ago. This is expected to remain true even in Matlab&#8217;s upcoming <a href="/articles/customizing-uifigures-part-1" rel="nofollow" target="_blank">web-based GUI system</a>, since Matlab would need to consciously disable HTML in its web components, and I see no reason for MathWorks to do so. In short, HTML parsing of GUI control strings is here to stay for the foreseeable future.</p>
<pre lang="matlab">
% note: no need to close HTML tags, e.g. </font></html>
uicontrol('Style','list', 'Position',[10,10,70,70], 'String', ...
          {'<html><font color="red">Hello</font></html>', 'world', ...
           '<html><font style="font-family:impact;color:green"><i>What a', ...
           '<html><font color="blue" face="Comic Sans MS">nice day!'});
</pre>
<p><center><figure style="width: 80px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Listbox with HTML items" src="https://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/html11.png" title="Listbox with HTML items" width="80" height="80" /><figcaption class="wp-caption-text">Listbox with HTML items</figcaption></figure></center><br />
While HTML formatting is generally frowned-upon compared to the alternatives, it provides a very quick and easy way to format text labels in various different manners, including using a combination of font faces, sizes, colors and other aspects (bold, italic, super/sub-script, underline etc.) within a single text label. This is naturally impossible to do with Matlab&#8217;s standard properties, but is super-easy with HTML placed in the label&#8217;s <b>String</b> property.<br />
<span id="more-6663"></span><br />
Unfortunately, while Java Swing (and therefore Matlab) honors only a [large] sub-set of HTML and CSS. The most important directives are parsed but <a href="http://stackoverflow.com/questions/7311235/java-html-css-in-swing-display-inline-not-working" rel="nofollow" target="_blank">some others are not</a>, and this is often difficult to debug. Luckily, using HTML and CSS there are often multiple ways to achieve the same visual effect, so if one method fails we can usually find an alternative. Such was the case when a reader <a href="/articles/html-support-in-matlab-uicomponents#comment-386047" rel="nofollow" target="_blank">asked me</a> why the following seemingly-simple HTML snippet failed to right-align his button label:</p>
<pre lang="matlab">
hButton.String = '<html><div style="text-align:right">text';
</pre>
<p>As I explained in my answer, it&#8217;s not Matlab that ignores the CSS <code>align</code> directive but rather the underlying Swing behavior, which snugly fits the text in the center of the button, and of course aligning text within a tight-fitting box has no effect. The workaround that I suggested simply forces Swing to use a non-tightly-fitting boundary box, within which we can indeed align the text:</p>
<pre lang="matlab">
pxPos = getpixelposition(hButton);
hButton.String = ['<html><div width="' num2str(pxPos(3)-20) 'px" align="right">text'];  % button margins use 20px
</pre>
<p><center><figure style="width: 140px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="centered (default) button label" src="https://undocumentedmatlab.com/images/button-center-align.gif" title="centered (default) button label" width="60" height="20" /> &nbsp; <img loading="lazy" decoding="async" alt="right-aligned button label" src="https://undocumentedmatlab.com/images/button-right-align.gif" title="right-aligned button label" width="60" height="20" /><figcaption class="wp-caption-text">Centered (default) and right-aligned button labels</figcaption></figure></center><br />
This solution is very easy to set up and maintain, and requires no special knowledge other than a bit of HTML/CSS, which most programmers know in this day and age.<br />
Of course, the solution relies on the actual button size. So, if the button is created with normalized units and changes its size when its parent container is resized, we&#8217;d need to set a callback function on the parent (e.g., <b>SizeChangedFcn</b> of a uipanel) to automatically adjust the button&#8217;s string based on its updated size. A better solution that would be independent of the button&#8217;s pixel-size and would work even when the button is resized needs to use Java.<br />
A related solution for table cells uses a different HTML-based trick: this time, we embed an HTML table cell within the Matlab control&#8217;s cell, employing the fact that HTML table cells can easily be aligned. We just need to ensure that the HTML cell is defined to be larger than the actual cell width, so that the alignment fits well. We do this by setting the HTML cell width to 9999 pixels (note that the <code>tr</code> and <code>td</code> HTML tags are necessary, but the <code>table</code> tag is optional):</p>
<pre lang="matlab">
uitable('Units','norm','Pos',[0,0,0.3,0.3], 'Data', ...
        {'Left', ...
         '<html><tr><td align=center width=9999>Center', ...
         '<html><tr><td align=right  width=9999>Right'});
</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Non-default alignment of uitable cells" src="https://undocumentedmatlab.com/images/uitable-cell-align.gif" title="Non-default alignment of uitable cells" width="200" height="40" /><figcaption class="wp-caption-text">Non-default alignment of uitable cells</figcaption></figure></center><br />
As noted above, a better solution might be to set the underlying Java component&#8217;s alignment properties (or in the case of the uitable, its underlying <code>JTable</code> component&#8217;s cellrenderer&#8217;s alignment). But in the general case, simple HTML such as above could well be sufficient.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/aligning-uicontrol-contents">Aligning uicontrol contents</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/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/spicing-up-matlab-uicontrol-tooltips" rel="bookmark" title="Spicing up Matlab uicontrol tooltips">Spicing up Matlab uicontrol tooltips </a> <small>Matlab uicontrol tooltips can be spiced-up using HTML and CSS, including fonts, colors, tables and images...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/aligning-uicontrol-contents/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing uifigures part 2</title>
		<link>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-uifigures-part-2</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 07 Sep 2016 17:00:57 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Iliya Romm]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6635</guid>

					<description><![CDATA[<p>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2">Customizing uifigures part 2</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/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger Iliya Romm of Israel&#8217;s Technion <a href="http://bcukurel.net.technion.ac.il" target="_blank" rel="nofollow">Turbomachinery and Heat Transfer Laboratory</a>. Today Iliya will discuss how Matlab&#8217;s new web-based figures can be customized with user-controlled CSS and JavaScript code.</i><br />
When we compare the documented properties of a &#8220;classic&#8221; <a href="http://www.mathworks.com/help/matlab/ref/uicontrol-properties.html" target="_blank" rel="nofollow"><code>uicontrol</code></a> with an App Designer control such as <a href="http://www.mathworks.com/help/matlab/ref/checkboxappdesigner-properties.html" target="_blank" rel="nofollow"><code>uicheckbox</code></a>, we see lists of 42 and 15 properties, respectively. At first glance, this implies that our ability to customize App Designer elements is relatively very limited. This is surely a disquieting conclusion, especially for those used to being able to change most aspect of their Matlab figures via Java. Fortunately, such a conclusion is quite far from reality, as we will shortly see.<br />
To understand this claim, we need to consider a <a href="/articles/customizing-uifigures-part-1" target="_blank" rel="nofollow">previous post on this blog</a>, where Yair discussed how uifigures are actually HTML webpages rendered by Matlab. As such, they have a DOM that can be accessed and manipulated through JavaScript commands to achieve various visual customizations. Today we&#8217;ll explore the structure of the uifigure webpage; take a look at some possibilities provided by the Dojo Toolkit; and see how to use Dojo to customize uifigure controls visually using CSS styles and/or HTML attributes.<br />
<center><a href="/images/uifigure_css1.gif" rel="nofollow" target="_blank"><img decoding="async" alt="User customizations of Matlab uifigures (click to zoom-in)" src="https://undocumentedmatlab.com/images/uifigure_css1.gif" title="User customizations of Matlab uifigures (click to zoom-in)" width="75%" style="max-width:1135px;" /></a><br />
User customizations of Matlab uifigures (click to zoom-in)</center><br />
<span id="more-6635"></span></p>
<h3 id="css">A brief introduction to CSS</h3>
<p><b>CSS</b> stands for <b>C</b>ascading <b>S</b>tyle <b>S</b>heets. As described on <a href="https://www.w3.org/standards/webdesign/htmlcss#whatcss" target="_blank" rel="nofollow">the official webpage</a> of W3C (which governs web standards):</p>
<blockquote><p>CSS is the language for describing the presentation of Web pages, including colors, layout, and fonts. CSS is independent of HTML. This is referred to as the separation of structure (or: content) from presentation.</p></blockquote>
<p>CSS rules (or &#8220;styles&#8221;) can be defined in one of three places:</p>
<ul>
<li>A separate file, such as the <i >main.css</i> that Matlab uses for uifigures (this file is found minified in <i>%matlabroot%\toolbox\matlab\uitools\uifigureappjs\release\gbtclient\css</i>)</li>
<li>An inline block inside the HTML&#8217;s <code>&lt;head&gt;</code> section</li>
<li>Directly within a DOM node</li>
</ul>
<p>Deciding which of the above to use, is largely a choice of the right tool for the job. <i>Usually</i>, the first two choices should be preferred, as they adhere to the &#8220;separation of structure and presentation&#8221; idea better. However, in the scope of this demonstration, we’ll be using mostly the 3rd option, because it allows us not to worry about possible CSS precedence issues (<a href="http://vanseodesign.com/css/css-specificity-inheritance-cascaade/" target="_blank" rel="nofollow">suggested read</a>).<br />
The syntax of CSS is generally: <code>selector { property: value }</code>, but it can have <a href="http://www.tutorialspoint.com/css/css_syntax.htm" target="_blank" rel="nofollow">other forms</a> as well.</p>
<h3 id="details">Getting down to business</h3>
<p>Let us consider a very basic uifigure that only contains a <a href="http://www.mathworks.com/help/matlab/ref/uitextarea.html" target="_blank" rel="nofollow"><code>uitextarea</code></a> and its label:<br />
<center><figure style="width: 282px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Simple demo uifigure with a TextArea and label" src="https://undocumentedmatlab.com/images/uifigure_css2.png" title="Simple demo uifigure with a TextArea and label" width="282" height="134" /><figcaption class="wp-caption-text">Simple demo uifigure with a TextArea and label</figcaption></figure></center><br />
The auto-generated code for it is:</p>
<div style="height: 300px; overflow: auto; margin-bottom: 10px;">
<pre lang="matlab">
classdef DOMdemo < matlab.apps.AppBase
    % Properties that correspond to app components
    properties (Access = public)
        UIFigure      matlab.ui.Figure           % UI Figure
        LabelTextArea matlab.ui.control.Label    % Text Area
        TextArea      matlab.ui.control.TextArea % This is some text.
    end
    methods (Access = private)
        % Code that executes after component creation
        function startupFcn(app)
        end
    end
    % App initialization and construction
    methods (Access = private)
        % Create UIFigure and components
        function createComponents(app)
            % Create UIFigure
            app.UIFigure = uifigure;
            app.UIFigure.Position = [100 100 280 102];
            app.UIFigure.Name = 'UI Figure';
            setAutoResize(app, app.UIFigure, true)
            % Create LabelTextArea
            app.LabelTextArea = uilabel(app.UIFigure);
            app.LabelTextArea.HorizontalAlignment = 'right';
            app.LabelTextArea.Position = [16 73 62 15];
            app.LabelTextArea.Text = 'Text Area';
            % Create TextArea
            app.TextArea = uitextarea(app.UIFigure);
            app.TextArea.Position = [116 14 151 60];
            app.TextArea.Value = {'This is some text.'};
        end
    end
    methods (Access = public)
        % Construct app
        function app = DOMdemo()
            % Create and configure components
            createComponents(app)
            % Register the app with App Designer
            registerApp(app, app.UIFigure)
            % Execute the startup function
            runStartupFcn(app, @startupFcn)
            if nargout == 0
                clear app
            end
        end
        % Code that executes before app deletion
        function delete(app)
            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end
</pre>
</div>
<p>Let's say we want to modify certain aspects of the <code>TextArea</code> widget, such as the text color, background, and/or horizontal alignment. The workflow for styling elements involves:</p>
<ol>
<li>Find the handle to the webfigure</li>
<li>Find the DOM node we want to modify</li>
<li>Find the property name that corresponds to the change we want</li>
<li>Find a way to manipulate the desired node from Matlab</li>
</ol>
<h4 id="webfigure">Step 1: Find the handle to the webfigure</h4>
<p>The first thing we need to do is to strategically place a bit of code that would allow us to get the URL of the figure so we can inspect it in our browser:</p>
<pre lang="matlab">
function startupFcn(app)
   % Customizations (aka "MAGIC GOES HERE"):
   warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
   warning off Matlab:structOnObject
   while true
      try
         win = struct(struct(struct(app).UIFigure).Controller).Container.CEF;
         disp(win.URL);
         break
      catch
         disp('Not ready yet!');
         pause(0.5); % Give the figure (webpage) some more time to load
      end
   end
end
</pre>
<p>This code waits until the page is <i>sufficiently</i> loaded, and then retrieve its local address (URL). The result will be something like this, which can be directly opened in any browser (outside Matlab):</p>
<pre lang="none">http://localhost:31415/toolbox/matlab/uitools/uifigureappjs/componentContainer.html?channel=/uicontainer/861ef484-534e-4a50-993e-6d00bdba73a5&snc=88E96E</pre>
<h4 id="DOM">Step 2: Find the DOM node that corresponds to the component that we want to modify</h4>
<p>Loading this URL in an external browser (e.g., Chrome, Firefox or IE/Edge) enables us to use web-development addins (e.g., FireBug) to inspect the page contents (source-code). </p>
<p>Note: in recent Matlab releases, the URL cannot be directly opened in a browser unless we first set Matlab to enable this (<a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-454673" target="_blank">thanks to Perttu</a>). We can turn on such browser debugging by running:</p>
<pre lang="matlab">matlab.internal.webwindow(' ', 'DebugPort',4040) %note: the space is important!</pre>
<p>before any other App, or kill all MatlabWindow processes (from the operating system's task manager) before running the command. Then browse http://localhost:4040/ in your browser - this will display a list of links, one link for each uifigure, based on the uifigure's title (name); click the requested uifigure's link to see and debug the figure's HTML/CSS contents.</p>
<p>Opening the URL inside a browser and inspecting the page contents, we can see its DOM:<br />
<center><a href="/images/uifigure_css3.png" rel="nofollow" target="_blank"><img decoding="async" alt="Inspecting the DOM in Firefox (click to zoom-in)" src="https://undocumentedmatlab.com/images/uifigure_css3.png" title="Inspecting the DOM in Firefox (click to zoom-in)" width="60%" style="max-width:1197px;" /></a><br />
Inspecting the DOM in Firefox (click to zoom-in)<br />
</center><br />
Notice the three <code>data-tag</code> entries marked by red frames. Any idea why there are exactly three nonempty tags like that? This is because our App Designer object, <code>app</code>, contains 3 declared children, as defined in:</p>
<pre lang="matlab">
createComponents(app):
    app.UIFigure = uifigure;
    app.LabelTextArea = uilabel(app.UIFigure);
    app.TextArea = uitextarea(app.UIFigure);
</pre>
<p>... and each of them is assigned a random hexadecimal id whenever the app is opened.<br />
Finding the relevant node involved some trial-and-error, but after doing it several times I seem to have found a consistent pattern that can be used to our advantage. Apparently, the nodes with <code>data-tag</code> are always above the element we want to style, sometimes as a direct parent and sometimes farther away. So why do we even need to bother with choosing more accurate nodes than these "tagged" ones? Shouldn't styles applied to the tagged nodes <i>cascade</i> down to the element we care about? Sure, <i>sometimes</i> it works like that, but we want to do better than "sometimes". To that end, we would like to select as relevant a node as possible.<br />
Anyway, the next step in the program is to find the data-tag that corresponds to the selected component. Luckily, there is a direct (undocumented) way to get it:</p>
<pre lang="matlab">
% Determine the data-tag of the DOM component that we want to modify:
hComponent = app.TextArea;  % handle to the component that we want to modify
data_tag = char(struct(hComponent).Controller.ProxyView.PeerNode.getId);  % this part is generic: can be used with any web-based GUI component
</pre>
<p>Let's take a look at the elements marked with blue and green borders (in that order) in the DOM screenshot. We see that the <code>data-tag</code> property is exactly one level above these elements, in other words, the first child of the tagged node is an element that contains a <code>widgetid</code> property. This property is very important, as it contains the <code>id</code> of the node that we actually want to change. Think pointers. To summarize this part:<br />
<center><b>data-tag  &nbsp; => &nbsp; widgetid  &nbsp; => &nbsp; widget "handle"</b></center><br />
We shall use this transformation in Step 4 below.<br />
I wanted to start with the blue-outlined element as it demonstrates this structure using distinct elements. The green-outlined element is slightly strange, as it contains a <code>widgetid</code> that points back to itself. Since this obeys the same algorithm, it's not a problem.</p>
<h4 id="propname">Step 3: Find the CSS property name that corresponds to the change we want</h4>
<p>There is no trick here: it's just a matter of going through <a href="http://www.w3schools.com/cssref/default.asp" target="_blank" rel="nofollow">a list of CSS properties</a> and choosing one that "sounds about right" (there are often several ways to achieve the same visual result with CSS). After we choose the relevant properties, we need to convert them to camelCase as per documentation of <a href="https://dojotoolkit.org/reference-guide/1.7/dojo/style.html#tips" target="_blank" rel="nofollow">dojo.style()</a>:</p>
<blockquote><p>If the CSS style property is hyphenated, the JavaScript property is camelCased. For example: "font-size" becomes "fontSize", and so on.</p></blockquote>
<p>Note that Matlab R2016a comes bundled with Dojo v1.10.4, rev. <a href="https://github.com/dojo/dojo/commit/f4fef7077dde783156c1ddd3b06464d236e5537c" target="_blank" rel="nofollow">f4fef70</a> (January 11 2015). Other Matlab releases will probably come with other Dojo versions. They will never be the latest version of Dojo, but rather a version that is 1-2 years old. We should keep this in mind when searching the Dojo documentation. We can get the current Dojo version as follows:</p>
<pre lang="matlab">
>> f=uifigure; drawnow; dojoVersion = matlab.internal.webwindowmanager.instance.windowList(1).executeJS('dojo.version'), delete(f)
dojoVersion =
{"major":1,"minor":10,"patch":4,"flag":"","revision":"f4fef70"}
</pre>
<p>This tells us that Dojo 1.10.4.f4fef70 is the currently-used version. We can use this information to browse the relevant documentation branch, as well as possibly use different Dojo functions/features.</p>
<h4 id="manipulate">Step 4: Manipulate the desired element from Matlab</h4>
<p>In this demo, we'll use a combination of several commands:</p>
<ul>
<li>{matlab.internal.webwindow.}executeJS() – For sending JS commands to the uifigure.</li>
<li><a href="https://dojotoolkit.org/reference-guide/1.10/dojo/query.html" target="_blank" rel="nofollow">dojo.query()</a> – for finding nodes inside the DOM.</li>
<li><a href="https://dojotoolkit.org/reference-guide/1.7/dojo/style.html" target="_blank" rel="nofollow">dojo.style()</a> (deprecated since v1.8) – for applying styles to the required nodes of the DOM.<br />
Syntax: dojo.style(node, style, value); </li>
<li><a href="https://dojotoolkit.org/reference-guide/1.7/dojo/setAttr.html" target="_blank" rel="nofollow">dojo.setAttr</a> (deprecated since v1.8) – for setting some non-style attributes.<br />
Syntax: dojo.setAttr(node, name, value); </li>
</ul>
<p>Consider the following JS commands:</p>
<ul>
<li>search the DOM for nodes having a data-tag attribute having the specified value, take their first child of type <code>&lt;div&gt;</code>, and return the value of this child's <code>widgetid</code> attribute:
<pre lang="matlab">['dojo.getAttr(dojo.query("[data-tag^=''' data_tag '''] > div")[0],"widgetid")']</pre>
</li>
<li>search the DOM for nodes with id of <code>widgetid</code>, then take the first element of the result and set its text alignment:
<pre lang="matlab">['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],"textAlign","center")']</pre>
</li>
<li>append the CSS style defined by <code>{SOME CSS STYLE}</code> to the page (this style can later be used by nodes):
<pre lang="matlab">['document.head.innerHTML += ''<style>{SOME CSS STYLE}</style>''']);</pre>
</li>
</ul>
<h4 id="all">Putting it all together</h4>
<p>It should finally be possible to understand the code that appears in the animated screenshot at the top of this post:</p>
<pre lang="matlab">
%% 1. Get a handle to the webwindow:
win = struct(struct(struct(app).UIFigure).Controller).Container.CEF;
%% 2. Find which element of the DOM we want to edit (as before):
data_tag = char(struct(app.TextArea).Controller.ProxyView.PeerNode.getId);
%% 3. Manipulate the DOM via a JS command
% ^ always references a class="vc-widget" element.
widgetId = win.executeJS(['dojo.getAttr(dojo.query("[data-tag^=''' data_tag '''] > div")[0],"widgetid")']);
% Change font weight:
dojo_style_prefix = ['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],'];
win.executeJS([dojo_style_prefix '"fontWeight","900")']);
% Change font color:
win.executeJS([dojo_style_prefix '"color","yellow")']);
% Add an inline css to the HTML <head>:
win.executeJS(['document.head.innerHTML += ''<style>'...
    '@-webkit-keyframes mymove {50% {background-color: blue;}}'...
    '@keyframes mymove {50% {background-color: blue;}}</style>''']);
% Add animation to control:
win.executeJS([dojo_style_prefix '"-webkit-animation","mymove 5s infinite")']);
% Change Dojo theme:
win.executeJS('dojo.setAttr(document.body,''class'',''nihilo'')[0]');
% Center text:
win.executeJS([dojo_style_prefix '"textAlign","center")']);
</pre>
<p>A similar method for center-aligning the items in a <a href="http://www.mathworks.com/help/matlab/ref/uilistbox.html" rel="nofollow" target="_blank">uilistbox</a> is <a href="http://stackoverflow.com/questions/38933254/how-to-customize-app-designer-figures-in-more-ways-than-officially-documented" rel="nofollow" target="_blank">described here</a> (using a CSS <code>text-align</code> directive).<br />
The only thing we need to ensure before running code that manipulates the DOM, is that the page is fully loaded. The easiest way is to include a <i><b>pause</b>()</i> of several seconds right after the <code>createComponents(app)</code> function (this will not interfere with the creation of the uifigure, as it happens on a different thread). I have been experimenting with <a href="https://github.com/StackOverflowMATLABchat/mlapptools/issues/1#issuecomment-241252137" target="_blank" rel="nofollow">another method</a> involving <code>webwindow</code>'s <code>PageLoadFinishedCallback</code> callback, but haven’t found anything elegant yet.</p>
<h3 id="warning">A few words of caution</h3>
<p>In this demonstration, we invoked Dojo functions via the webwindow's JS interface. For something like this to be possible, there has to exist some form of “bridge” that translates Matlab commands to JS commands issued to the browser and control the DOM. We also know that this bridge has to be bi-directional, because binding Matlab callbacks to uifigure actions (e.g. <code>ButtonPushFcn</code> for uibuttons) is a documented feature.<br />
The extent to which the bridge might allow malicious code to control the Matlab process needs to be investigated. Until then, the ability of webwindows to execute arbitrary JS code should be considered a known vulnerability. For more information, see <a href="https://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank" rel="nofollow">XSS</a> and <a href="https://en.wikipedia.org/wiki/Cross-site_scripting#Related_vulnerabilities" target="_blank" rel="nofollow">related</a> vulnerabilities.</p>
<h3 id="conclusion">Final remarks</h3>
<p>It should be clear now that there are actually lots of possibilities afforded by the new uifigures for user customizations. One would hope that future Matlab releases will expose easier and more robust hooks for CSS/JS customizations of uifigure contents. But until that time arrives (if ever), we can make do with the mechanism shown above.<br />
Readers are welcome to visit the <a href="https://github.com/StackOverflowMATLABchat/mlapptools" target="_blank" rel="nofollow">GitHub project</a> dedicated to manipulating uifigures using the methods discussed in this post. Feel free to comment, suggest improvements and ideas, and of course submit some pull requests 🙂<br />
p.s. – it turns out that uifigures can also display <a href="https://www.w3.org/Math/" rel="nofollow" target="_blank">MathML</a>. But this is a topic for another post...</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2">Customizing uifigures part 2</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/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Rich-contents log panel</title>
		<link>https://undocumentedmatlab.com/articles/rich-contents-log-panel?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rich-contents-log-panel</link>
					<comments>https://undocumentedmatlab.com/articles/rich-contents-log-panel#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 18 Sep 2013 14:00:16 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4180</guid>

					<description><![CDATA[<p>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/rich-contents-log-panel">Rich-contents log panel</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/rich-matlab-editbox-contents" rel="bookmark" title="Rich Matlab editbox contents">Rich Matlab editbox contents </a> <small>The Matlab editbox uicontrol does not handle HTML contents as do other uicontrols. In this article I show how this limitation can be removed....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/aligning-uicontrol-contents" rel="bookmark" title="Aligning uicontrol contents">Aligning uicontrol contents </a> <small>Matlab uicontrols can often be customized using plain HTML/CSS, without need for advanced Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I often include a log panel in Matlab applications that process data. By sending messages to the log panel, I can avoid msgbox popups and Command Window messages that interfere with the regular workflow. In Matlab, such log panels typically use a simple listbox or editbox control. The problem with this is that all text messages in the log panel look the same. Matlab does not have a documented way to highlight specific messages or words. Well, this has never stopped us before, has it? 🙂</p>
<h3 id="listbox">The listbox solution</h3>
<p>I have often noted in past articles that <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">most Matlab uicontrols support HTML formatting</a>. We can use a listbox control for our log panel, and use HTML formatting for the various log messages, based on their severity or content. For example:<br />
<figure id="attachment_27" aria-describedby="caption-attachment-27" style="width: 100px" class="wp-caption alignright"><img loading="lazy" decoding="async" class="size-full wp-image-27" title="Listbox with HTML colored items" src="https://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/html11.png" alt="Listbox with HTML'ed items" width="70" height="70" /><figcaption id="caption-attachment-27" class="wp-caption-text">Listbox with HTML colored items</figcaption></figure></p>
<pre lang='matlab'>
uicontrol('Style','list', 'Position',[10,10,70,70], 'String', ...
   {'<html><font color="red">Hello</font></html>', 'world', ...
    '<html><font style="font-family:impact;color:green"><i>What a', ...   % note: </i></font></html> are not needed
    '<html><font color="blue" face="Comic Sans MS">nice day!</font>'});   % note: </html> is not needed
</pre>
<p>Rich listboxes such as this are very easy to set up and use. As I just showed, all it takes is sending an HTML string to a regular listbox. The down-side is that listboxes only display single-line messages, so if our message is too long we need to manually split it into separate listbox lines, which is rather inconvenient. Using HTML &lt;br/&gt; does not work since the allocated line height remains unchanged. We can fix this by playing around with the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/">underlying Java object</a>&#8216;s RowHeight property, but that again is rather inconvenient.</p>
<h3 id="editbox">The editbox solution</h3>
<p>Instead of a listbox, I often use a multi-line editbox. Unfortunately, HTML is not as-easy to use in multi-line editbox contents, but as I have <a target="_blank" href="/articles/rich-matlab-editbox-contents/">shown before</a>, it is indeed possible and actually quite powerful. In fact, I am using such an editbox-based log panel&#8217;s in my online presentation at the <a target="_blank" rel="nofollow" href="http://engage.vevent.com/index.jsp?eid=1972&#038;seid=900">MATLAB Computational Finance Virtual Conference</a> tomorrow (Thursday Sep 19, 2013 at 2pm EST / 8pm CEST, see details below):<br />
<center><figure style="width: 650px" class="wp-caption aligncenter"><a target="_blank" href="/images/demo_screenshot2.png"><img loading="lazy" decoding="async" alt="Real-time trading system demo in Matlab (click to zoom)" src="https://undocumentedmatlab.com/images/demo_screenshot2.png" title="Real-time trading system demo in Matlab (click to zoom)" width="650" height="398" /></a><figcaption class="wp-caption-text">Real-time trading system demo in Matlab (click to zoom)</figcaption></figure></center><br />
We can see in the screenshot that some log messages (the red warning message) can span multiple lines. Moreover, the panels can be interactively dragged/resized, making the multi-line log messages &#8220;flow&#8221; based on available space. So using an editbox is preferable to a listbox. The solution implemented in the demo is quite simple:<br />
<span id="more-4180"></span><br />
First we define the logging utility function (the icon filenames may need to be changed based on your Matlab release):</p>
<pre lang="matlab">
function logMessage(jEditbox,text,severity)
   % Ensure we have an HTML-ready editbox
   HTMLclassname = 'javax.swing.text.html.HTMLEditorKit';
   if ~isa(jEditbox.getEditorKit,HTMLclassname)
      jEditbox.setContentType('text/html');
   end
   % Parse the severity and prepare the HTML message segment
   if nargin < 3,  severity='info';  end
   switch lower(severity(1))
      case 'i',  icon = 'greenarrowicon.gif'; color='gray';
      case 'w',  icon = 'demoicon.gif';       color='black';
      otherwise, icon = 'warning.gif';        color='red';
   end
   icon = fullfile(matlabroot,'toolbox/matlab/icons',icon);
   iconTxt =['<img decoding="async" src="file:///',icon,'" height=16 width=16/>'];
   msgTxt = ['&nbsp;<font color=',color,'>',text,'</font>'];
   newText = [iconTxt,msgTxt];
   endPosition = jEditbox.getDocument.getLength;
   if endPosition>0, newText=['<br />' newText];  end
   % Place the HTML message segment at the bottom of the editbox
   currentHTML = char(jEditbox.getText);
   jEditbox.setText(strrep(currentHTML,[60 '/body>'],newText));
   endPosition = jEditbox.getDocument.getLength;
   jEditbox.setCaretPosition(endPosition); % end of content
end
</pre>
<p>Next, we initialize the log panel editbox and store the editbox&#8217;s underlying Java component (<code>jEditbox</code>) using the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i></a> utility:</p>
<pre lang='matlab'>
% Prepare the log editbox
hLogPanel = uicontrol('style','edit', 'max',5, 'Parent',hLeftBottomPanel, 'Units','norm', 'Position',[0,0.2,1,0.8], 'Background','w');
% Get the underlying Java editbox, which is contained within a scroll-panel
jScrollPanel = findjobj(hLogPanel);
try
    jScrollPanel.setVerticalScrollBarPolicy(jScrollPanel.java.VERTICAL_SCROLLBAR_AS_NEEDED);
    jScrollPanel = jScrollPanel.getViewport;
catch
    % may possibly already be the viewport, depending on release/platform etc.
end
jEditbox = handle(jScrollPanel.getView,'CallbackProperties');
</pre>
<p>Now, we can use this logging utility function to log messages in our application. For example:</p>
<pre lang="matlab">
logMessage(jEditbox, 'a regular info message...');
logMessage(jEditbox, 'a warning message...', 'warn');
logMessage(jEditbox, 'an error message!!!', 'error');
logMessage(jEditbox, 'a regular message again...', 'info');
</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Rich editbox contents (a log file)" src="https://undocumentedmatlab.com/images/editbox10.png" title="Rich editbox contents (a log file)" width="200" height="60" /><figcaption class="wp-caption-text">Rich editbox contents (a log file)</figcaption></figure></center><br />
HTML editboxes are normally editable, images included. In actual applications, we usually wish to prevent editing the displayed log. To do this, we simply call <code>jEditbox.<i>setEditable(false)</i></code>. Similarly, it is easy to set-up a Matlab callback-function to handle hyperlink clicks in the log panel (unlike what we might think, this is not handled automatically by the HTML processing engine):</p>
<pre lang='matlab'>
% Prevent user editing in the log-panel
jEditbox.setEditable(false);
% Set-up a Matlab callback function to handle hyperlink clicks
set(jEditbox,'HyperlinkUpdateCallback',@linkCallbackFcn);
</pre>
<h3 id="conf">About the MATLAB Computational Finance Virtual Conference and my presentation</h3>
<p>The MATLAB Computational Finance Virtual Conference is a one-day (Thursday Sep 19, 2013) event of hour-long presentations by industry professionals that showcase real-world examples demonstrating how financial-industry researchers and developers can excel at their jobs, improve their research and business processes, reduce costs, and mitigate risks by using Matlab. <a target="_blank" rel="nofollow" href="http://engage.vevent.com/registr_form.jsp?eid=1972&#038;seid=900&#038;language-code=en&#038;country-code=US&#038;page=1&#038;no-login=false">Registration</a> to the conference is free and it&#8217;s a virtual conference, so there&#8217;s no need for a tie and jacket and you&#8217;re welcome to join&#8230;<br />
<center><a target="_blank" rel="nofollow" href="http://engage.vevent.com/index.jsp?eid=1972&#038;seid=900"><img loading="lazy" decoding="async" alt="MATLAB Computational Finance Conference 2013" src="https://undocumentedmatlab.com/images/MATLAB_Computational_Finance_Conference_2013.jpg" title="MATLAB Computational Finance Conference 2013" width="600" height="112" /></a></center><br />
My presentation on &#8220;<i>A Real-Time Trading System in MATLAB</i>&#8220;, is scheduled for 2pm EST / 8pm CEST. Following a half-hour presentation, I will answer audience questions online. The presentation slides can be <a target="_blank" href="/files/Matlab%20real-time%20trading%20presentation.pdf">downloaded here</a>. <a target="_blank" rel="nofollow" href="https://www.youtube.com/watch?v=e4bdKcFl4GA">Here</a> is the recorded presentation video:<br />
<center><object id="vvq-17637-youtube-1" style="visibility: visible; display: block !important;" width="425" height="344" data="https://www.youtube.com/v/e4bdKcFl4GA&amp;rel=0&amp;fs=1&amp;showsearch=0&amp;showinfo=0" type="application/x-shockwave-flash"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /></object></center><br />
The demo system&#8217;s user interface showcases the hidden visualization and interactivity potential of Matlab for tracking order executions and charting financial time-series in real time. The undocumented features used in the demo include:</p>
<ul>
<li><a target="_blank" href="/articles/displaying-animated-gifs/">Animated GIF logo image</a> (rotating Dollar sign)</li>
<li><a target="_blank" href="/articles/uitable-customization-report/">Customized data table</a></li>
<li><a target="_blank" href="/articles/rich-matlab-editbox-contents/">Log box with rich HTML contents</a>: icons and color-coded messages (as shown above)</li>
<li><a target="_blank" href="/articles/uisplitpane/">Draggable (resizable) panel borders</a> (note that this feature does not work in the new <a target="_blank" href="/articles/hg2-update/">HG2</a> &#8211; I hope it will be fixed by the time that HG2 is released)</li>
<li><a target="_blank" href="/articles/minimize-maximize-figure-window/">Maximized figure window</a></li>
</ul>
<p>So, even if you&#8217;re not interested in real-time financial trading with Matlab, you might find it interesting to see the neat things that Matlab can do using a Java API interface and a few undocumented GUI tricks (such as the rich-contents log that I explained above).<br />
The demo source code is provided <a target="_blank" href="/files/Matlab%20trading%20demo.zip">here</a> (tradingDemo.m and supporting files). Note that this is provided as-is, free of charge but without any warranty or support. You would naturally need <a target="_blank" href="/ib-matlab/">IB-Matlab</a> and an Interactive Brokers account to run it. But you can reuse parts of the source code in your Matlab programs even without an IB account or IB-Matlab.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/rich-contents-log-panel">Rich-contents log panel</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/rich-matlab-editbox-contents" rel="bookmark" title="Rich Matlab editbox contents">Rich Matlab editbox contents </a> <small>The Matlab editbox uicontrol does not handle HTML contents as do other uicontrols. In this article I show how this limitation can be removed....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/aligning-uicontrol-contents" rel="bookmark" title="Aligning uicontrol contents">Aligning uicontrol contents </a> <small>Matlab uicontrols can often be customized using plain HTML/CSS, without need for advanced Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/gui-integrated-html-panel" rel="bookmark" title="GUI integrated HTML panel">GUI integrated HTML panel </a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/rich-contents-log-panel/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Real-time trading system demo</title>
		<link>https://undocumentedmatlab.com/articles/real-time-trading-system-demo?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=real-time-trading-system-demo</link>
					<comments>https://undocumentedmatlab.com/articles/real-time-trading-system-demo#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 29 May 2013 13:15:21 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[uisplitpane]]></category>
		<category><![CDATA[uitable]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3825</guid>

					<description><![CDATA[<p>A real-time Matlab-based end-to-end trading system demo is presented </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo">Real-time trading system demo</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/jtattoo-look-and-feel-demo" rel="bookmark" title="JTattoo look-and-feel demo">JTattoo look-and-feel demo </a> <small>A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/nyc-visit-may-2013" rel="bookmark" title="New York City visit, 21-24 May 2013">New York City visit, 21-24 May 2013 </a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I gave a presentation at the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/agenda.html">MATLAB Computational Finance Conference</a> in New York. The room was packed-full with close to 200 professionals in the finance industry. The energy and feedback were tremendous, it was a great experience. The presentation (PDF format) is provided <a target="_blank" href="/files/Matlab%20real-time%20trading%20presentation.pdf">here</a>.<br />
I presented a demo application that showed how Matlab can be used to create a full end-to-end trading system, highlighting Matlab&#8217;s potential as a platform of choice. I used <a target="_blank" rel="nofollow" href="http://www.interactivebrokers.com/en/main.php">Interactive Brokers</a> to demonstrate live market data feed and account/portfolio input, as well as for sending trading orders to the market, via the <a target="_blank" href="/ib-matlab/">IB-Matlab</a> connector:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" href="/images/demo_screenshot.png"><img loading="lazy" decoding="async" alt="Real-time trading system demo in Matlab (click for details)" src="https://undocumentedmatlab.com/images/demo_screenshot.png" title="Real-time trading system demo in Matlab (click for details)" width="560" height="289" /></a><figcaption class="wp-caption-text">Real-time trading system demo in Matlab (click for details)</figcaption></figure></center><br />
The demo system&#8217;s user interface showcased the hidden visualization and interactivity potential of MATLAB for tracking order executions and charting financial time-series in real time. The undocumented features used in the demo include:</p>
<ul>
<li><a target="_blank" href="/articles/displaying-animated-gifs/">Animated GIF logo image</a> (rotating Dollar sign)</li>
<li><a target="_blank" href="/articles/uitable-customization-report/">Customized data table</a></li>
<li><a target="_blank" href="/articles/rich-matlab-editbox-contents/">Log box with rich HTML contents</a>: icons and color-coded messages</li>
<li><a target="_blank" href="/articles/uisplitpane/">Draggable (resizable) panel borders</a> (note that this feature does not work in the new <a target="_blank" href="/articles/hg2-update/">HG2</a> &#8211; I hope it will be fixed by the time that HG2 is released)</li>
<li><a target="_blank" href="/articles/minimize-maximize-figure-window/">Maximized figure window</a></li>
</ul>
<p>The demo source code is provided <a target="_blank" href="/files/Matlab%20trading%20demo.zip">here</a> (tradingDemo.m and supporting files). Note that this is provided as-is, free of charge but without any warranty or support. You would naturally need <a target="_blank" href="/ib-matlab/">IB-Matlab</a> and an Interactive Brokers account to run it.<br />
If you came to the conference, I want to thank you for being an excellent audience. I hope we have a chance to work together on your projects. Shoot me <a href="mailto: altmany @gmail.com?subject=Matlab assistance&amp;body=Hi Yair, &amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab assistance&amp;body=Hi Yair, '); return false;">an email</a> if you&#8217;d like my help in any consulting, training or development work.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo">Real-time trading system demo</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/jtattoo-look-and-feel-demo" rel="bookmark" title="JTattoo look-and-feel demo">JTattoo look-and-feel demo </a> <small>A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/nyc-visit-may-2013" rel="bookmark" title="New York City visit, 21-24 May 2013">New York City visit, 21-24 May 2013 </a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/real-time-trading-system-demo/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Displaying animated GIFs</title>
		<link>https://undocumentedmatlab.com/articles/displaying-animated-gifs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=displaying-animated-gifs</link>
					<comments>https://undocumentedmatlab.com/articles/displaying-animated-gifs#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 22 May 2013 18:00:38 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3772</guid>

					<description><![CDATA[<p>It is possible to easily display animated images in Matlab figure windows. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-animated-gifs">Displaying animated GIFs</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/animated-busy-spinning-icon" rel="bookmark" title="Animated busy (spinning) icon">Animated busy (spinning) icon </a> <small>An animated spinning icon label can easily be embedded in Matlab GUI. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</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/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Displaying images in Matlab figures has always been sort-of awkward. We need to read the image file into a Matlab matrix (possibly with accompanying colormap), then create an invisible axis in our figure window, and finally display the image data within this axis, typically with the <i><b>imagesc</b></i> function. In practice, this  is not as difficult as it may seem, and can be done in 3 lines of code (<i><b>imread(); axes(); imagesc();</b></i>). To display images in uicontrols, we need to set their <b>CData</b> property with the image data. Unfortunately, this is only supported for static (non-animated) images.<br />
But what if we want to display an animated image? There are several image formats that enable animation, GIF being the most well-known. Animated GIFs are used ubiquitously, for anything from logos to simple visualizations. I often use them myself in my utilities and this blog, to illustrate <a target="_blank" href="/articles/uiinspect/">functionality</a> or <a target="_blank" href="/articles/splash-window-for-deployed-applications/">usage</a>. Creating animated GIFs is so easy &#8212; I often use <a target="_blank" rel="nofollow" href="http://picasion.com/">Picasion</a>, but there are numerous alternatives.<br />
So let&#8217;s assume that I have the animated GIF featured here:<br />
<figure style="width: 64px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="animated GIF" src="https://undocumentedmatlab.com/images/dollar_animated_64x64_transparent.gif" title="animated GIF" width="64" height="64" /><figcaption class="wp-caption-text">animated GIF</figcaption></figure><br />
This example serves as the logo in a <a target="_blank" href="/articles/real-time-trading-system-demo/">demo live trading application</a> that I&#8217;ll present tomorrow at the <a target="_blank" href="/articles/nyc-visit-may-2013/">MATLAB Computational Finance Conference</a>.<br />
To display this image in a Matlab GUI, we could use a <a target="_blank" href="/articles/gui-integrated-browser-control/">mini-browser control that we can easily integrate</a> within the figure. But an even simpler and less resource-intensive solution is to <a target="_blank" href="/articles/gui-integrated-html-panel/">integrate an HTML panel</a>:</p>
<pre lang='matlab'>
hFig = figure('Color','w');
je = javax.swing.JEditorPane('text/html', '<html><img decoding="async" src="file:/C:\Yair\animated.gif"/></html>');
[hj, hc] =  javacomponent(je,[],hFig);
set(hc, 'pos', [10,10,70,70])
</pre>
<p><center><figure style="width: 250px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Animated GIF image integrated in Matlab figure" src="https://undocumentedmatlab.com/images/dollar_animated_w.gif" title="Animated GIF image integrated in Matlab figure" width="227" height="176" /><figcaption class="wp-caption-text">Animated GIF image integrated in Matlab figure</figcaption></figure></center><br />
<span id="more-3772"></span><br />
Notes:</p>
<ol>
<li>Although the GIF image is 64&#215;64 pixels, we set the containing <code>JEditorPane</code>&#8216;s size to 70&#215;70, to account for the border and a small margin. You can obviously play with the size.</li>
<li>The image source was specified using the <code>file:/</code> protocol, as I explained <a target="_blank" href="/articles/images-in-matlab-uicontrols-and-labels/">here</a>.</li>
</ol>
<p>If our animated GIF uses transparency, we should set the container&#8217;s background to the same color as the figure, as I explained <a target="_blank" href="/articles/javacomponent-background-color/">here</a>:</p>
<pre lang='matlab'>
bgcolor = num2cell(get(hFig,'Color'));
hj.setBackground(java.awt.Color(bgcolor{:}));
</pre>
<p><center><figure style="width: 320px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Animated transparent GIF image integrated in Matlab figure" src="https://undocumentedmatlab.com/images/dollar_animated_t.gif" title="Animated transparent GIF image integrated in Matlab figure" width="227" height="176" /><figcaption class="wp-caption-text">Animated transparent GIF image integrated in Matlab figure</figcaption></figure></center><br />
For anyone wondering, we could just as easily have used a simple <code>JLabel</code> rather than a <code>JEditorPane</code> (see <a target="_blank" href="/articles/customizing-matlab-labels/">here</a>). The only difference is that we would need to also take care of the background:</p>
<pre lang='matlab'>
hFig = figure('Color','w');
je = javax.swing.JLabel('<html><img decoding="async" src="file:/C:\Yair\animated.gif"/></html>');
je.setBackground(java.awt.Color(1,1,1));  %=white
[hj, hc] =  javacomponent(je,[],hFig);
set(hc, 'pos', [10,10,70,70])
</pre>
<p>We can similarly display animated GIFs on any uicontrol, due to the inherent nature of uicontrols that they <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">accept HTML contents</a>. So, we can place our animated GIF in buttons, drop-downs, listboxes etc. It&#8217;s not as straight-forward in drop-downs/listboxes as it is in buttons, but then again not many people need animated images in drop-downs or listboxes as they do in buttons. For push/toggle buttons, checkboxes and radio-buttons, displaying animated GIFs is trivially simple:</p>
<pre lang='matlab'>
h1 = uicontrol('style','push',  'pos', [10,10,70,70], 'String','<html><img decoding="async" src="file:/C:\Yair\animated.gif"/></html>');
h2 = uicontrol('style','check', 'pos', [90,10,70,70], 'String','<html><img decoding="async" src="file:/C:\Yair\animated.gif"/></html>');
h3 = uicontrol('style','radio', 'pos',[170,10,70,70], 'String','<html><img decoding="async" src="file:/C:\Yair\animated.gif"/></html>');
</pre>
<p><center><figure style="width: 350px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Animated transparent GIF image integrated in Matlab uicontrols" src="https://undocumentedmatlab.com/images/dollar_animated_u.gif" title="Animated transparent GIF image integrated in Matlab uicontrols" width="264" height="161" /><figcaption class="wp-caption-text">Animated transparent GIF image integrated in Matlab uicontrols</figcaption></figure></center><br />
The standard documented manner of displaying animated GIFs in Matlab is to <i><b>imread</b></i> all image frames from the GIF file, then start a <i><b>timer</b></i> that will periodically replace the axes image (or uicontrol <b>CData</b> property) with the next image frame in an endless loop. This is relatively tedious to set up, results in noticeable flicker and is relatively CPU intensive. I believe that the undocumented mechanism I&#8217;ve explained above is simpler to code and lighter on graphic resources.<br />
Today&#8217;s article was a tribute to two old friends, whom I never met in person so far: a client who has recently asked me about this issue, and a member of a Graphics team who said he liked my related posts. I hope to meet both of them at the conference tomorrow. If you are interested in any aspect of computational finance, you will surely find some interesting presentations at this conference. So if you&#8217;re in town, I urge you to attend (free <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/registration.html">registration</a>; my presentation is scheduled for 4:50pm). Otherwise, we could meet anywhere in New York tomorrow (Friday May 24), to discuss how I could bring value to your needs, either financial-oriented or not.<br />
<center><a href="/articles/nyc-visit-may-2013/"><img loading="lazy" decoding="async" title="Matlab Computational Finance Conference - 23 May 2013" src="https://undocumentedmatlab.com/images/conference_invite_animated.gif" alt="Matlab Computational Finance Conference - 23 May 2013" width="324" height="86"/></a></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-animated-gifs">Displaying animated GIFs</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/animated-busy-spinning-icon" rel="bookmark" title="Animated busy (spinning) icon">Animated busy (spinning) icon </a> <small>An animated spinning icon label can easily be embedded in Matlab GUI. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</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/html-support-in-matlab-uicomponents" rel="bookmark" title="HTML support in Matlab uicomponents">HTML support in Matlab uicomponents </a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/displaying-animated-gifs/feed</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
			</item>
		<item>
		<title>Images in Matlab uicontrols &#038; labels</title>
		<link>https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=images-in-matlab-uicontrols-and-labels</link>
					<comments>https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 17 Oct 2012 18:00:57 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3177</guid>

					<description><![CDATA[<p>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels">Images in Matlab uicontrols &amp; labels</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/icon-images-in-matlab-uicontrols" rel="bookmark" title="Icon images &amp; text in Matlab uicontrols">Icon images &amp; text in Matlab uicontrols </a> <small>HTML can be used to add image icons to Matlab listbox and popup (drop-down) controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparency-in-uicontrols" rel="bookmark" title="Transparency in uicontrols">Transparency in uicontrols </a> <small>Matlab uicontrols' CData property can be customized to provide background transparency....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-labels" rel="bookmark" title="Customizing Matlab labels">Customizing Matlab labels </a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A couple of weeks ago, a reader <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/#comment-110444">here</a> asked how to integrate images in Matlab labels. I see quite a few queries about this, so I wanted to take today&#8217;s opportunity to explain how this can be done, and how to avoid common pitfalls.<br />
In fact, there are two main methods of displaying images in Matlab GUI &#8211; the documented method, and the undocumented one:</p>
<h3 id="documented">The documented method</h3>
<p>Some Matlab uicontrols (buttons, radio and checkboxes) have the <a target="_blank" rel="nofollow" href="http://www.mathworks.co.uk/help/matlab/ref/uicontrol_props.html#bqxoijz"><b>CData</b></a> property that can be used to load and display an image. For example:</p>
<pre lang='matlab'>
imgData = imread('myImage.jpg');   % or: imread(URL)
hButton = uicontrol('CData',imgData, ...);
</pre>
<p>While label uicontrols (<i><b>uicontrol</b>(&#8216;style&#8217;,&#8217;text&#8217;, &#8230;)</i>) also have the <b>CData</b> property, it has no effect on these controls. Instead, we can create an invisible axes that displays the image using the <i><b>image</b></i> function.</p>
<h3 id="undocumented">The undocumented method</h3>
<h4 id="web">web-based images</h4>
<p>I&#8217;ve already written extensively about Matlab&#8217;s <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">built-in support for HTML</a> in many of its controls. The supported HTML subset includes the &lt;img&gt; tag, and can therefore display images. For example:</p>
<pre lang='matlab' escaped="true">
htmlStr = '<html><b>Logo</b>: <img decoding="async" src="https://undocumentedmatlab.com/images/logo_68x60.png"/></html>';
hButton = uicontrol('Position',[10,10,120,70], 'String',htmlStr, 'Background','white');
</pre>
<p><center><figure style="width: 150px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uicontrol with HTML image" src="https://undocumentedmatlab.com/images/button_image.png" title="uicontrol with HTML image" width="120" height="70" /><figcaption class="wp-caption-text">uicontrol with HTML image</figcaption></figure></center></p>
<h4 id="local">local images</h4>
<p>Note that the image src (filename) needs to be formatted in a URL-compliant format such as <code>'http://www.website.com/folder/image.gif'</code> or <code>'file:/c:/folder/subfolder/img.png'</code>. If we try to use a non-URL-format filename, the image will not be rendered, only a placeholder box:</p>
<pre lang='matlab' escaped="true">
uicontrol('Position',..., 'String','<html><img decoding="async" src="img.gif"/></html>');  %bad
uicontrol('Style','list', ... 'String',{...,'<html><img decoding="async" src="img.gif"/></html>'});  %bad
</pre>
<p><center><figure style="width: 170px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Ill-specified HTML images in Matlab uicontrols" src="https://undocumentedmatlab.com/images/html_noimg1.png" title="Ill-specified HTML images in Matlab uicontrols" width="70" height="70"/> <img loading="lazy" decoding="async" alt="Ill-specified HTML images in Matlab uicontrols" src="https://undocumentedmatlab.com/images/html_noimg2.png" title="Ill-specified HTML images in Matlab uicontrols" width="70" height="70"/><figcaption class="wp-caption-text">Ill-specified HTML images in Matlab uicontrols</figcaption></figure></center><br />
Instead, we need to use correct URI syntax when specifying local images, which means using the <code>'file:/'</code> protocol prefix and the <code>'/'</code> folder separator: <span id="more-3177"></span></p>
<pre lang='matlab' escaped="true">
>> iconsFolder = fullfile(matlabroot,'/toolbox/matlab/icons/');
>> iconUrl = strrep(['file:/' iconsFolder 'matlabicon.gif'],'\','/');
>> str = ['<html><img decoding="async" src="' iconUrl '"/></html>']
str =
<html><img decoding="async" src="file:/C:/Program Files/MATLAB/ ..... /icons/matlabicon.gif"/></html>
>> uicontrol('Position',..., 'String',str);
>> uicontrol('Style','list', ... str});
</pre>
<p><center><figure style="width: 170px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Correctly-specified HTML images in Matlab uicontrols" src="https://undocumentedmatlab.com/images/html_img.png" title="Correctly-specified HTML images in Matlab uicontrols" width="70" height="70"/> <img loading="lazy" decoding="async" alt="Correctly-specified HTML images in Matlab uicontrols" src="https://undocumentedmatlab.com/images/html_img2.png" title="Correctly-specified HTML images in Matlab uicontrols" width="70" height="70"/><figcaption class="wp-caption-text">Correctly-specified HTML images in Matlab uicontrols</figcaption></figure></center><br />
A similar pitfall exists when trying to integrate images in GUI control tooltips. I already discussed this issue <a target="_blank" href="/articles/spicing-up-matlab-uicontrol-tooltips/">here</a>.<br />
You can use HTML to resize the images, using the &lt;img&gt; tag&#8217;s <i>width, height</i> attributes. However, beware that enlarging an image might introduce pixelization effects. I discussed image resizing <a target="_blank" href="/articles/customizing-menu-items-part-3/#custom">here</a> &#8211; that article was in the context of menu-item icons, but the discussion of image resizing also applies in this case.</p>
<h4 id="labels">images in text labels</h4>
<p>As for text labels, since text-style uicontrols do not unfortunately support HTML, we can use the equivalent Java <code>JLabel</code>s, as I have explained <a target="_blank" href="/articles/customizing-matlab-labels/">here</a>. Here too, we need to use the <code>'file:/'</code> protocol prefix and the <code>'/'</code> folder separator if we want to use local files rather than internet files (http://&#8230;).</p>
<h4 id="java">Java customizations</h4>
<p>Using a uicontrol&#8217;s <a target="_blank" href="/articles/findjobj-find-underlying-java-object/">underlying Java component</a>, we can customize the displayed image icon even further. For example, we can specify a different icon for selected/unselected/disabled/hovered/pressed/normal button states, as I have explained <a target="_blank" href="/articles/button-customization/">here</a>. In fact, we can even specify a unique icon that will be used for the mouse cursor when it hovers on the control:<br />
<center><figure style="width: 170px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/cursor3.png" alt="Custom cursor" title="Custom cursor" width="84" height="44" /> <img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/button_cursor_hand.png" alt="Custom cursor" title="Custom cursor" width="70" height="44" /><figcaption class="wp-caption-text">Custom uicontrol cursors</figcaption></figure></center></p>
<h4 id="R2019b">R2019b and newer</h4>
<p>Iin R2019b and later, unless you specify the image size nothing will be shown. A solution is presented in <a href="https://www.mathworks.com/matlabcentral/answers/497260-figure-uitable-does-not-display-html-image-in-2019b#answer_411812" rel="nofollow" target="_blank">this answer</a></p>
<pre lang="Matlab">str = ['<html><img loading="lazy" decoding="async" src="file:/' iconUrl '" height="16" width="16"></html>'];</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels">Images in Matlab uicontrols &amp; labels</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/icon-images-in-matlab-uicontrols" rel="bookmark" title="Icon images &amp; text in Matlab uicontrols">Icon images &amp; text in Matlab uicontrols </a> <small>HTML can be used to add image icons to Matlab listbox and popup (drop-down) controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparency-in-uicontrols" rel="bookmark" title="Transparency in uicontrols">Transparency in uicontrols </a> <small>Matlab uicontrols' CData property can be customized to provide background transparency....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-labels" rel="bookmark" title="Customizing Matlab labels">Customizing Matlab labels </a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/panel-level-uicontrols" rel="bookmark" title="Panel-level uicontrols">Panel-level uicontrols </a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels/feed</wfw:commentRss>
			<slash:comments>29</slash:comments>
		
		
			</item>
	</channel>
</rss>
