<?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>Tooltip &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/tooltip/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 03 Nov 2011 02:05:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Multi-line tooltips</title>
		<link>https://undocumentedmatlab.com/articles/multi-line-tooltips?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multi-line-tooltips</link>
					<comments>https://undocumentedmatlab.com/articles/multi-line-tooltips#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 03 Nov 2011 02:05:36 +0000</pubDate>
				<category><![CDATA[GUI]]></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[Pure Matlab]]></category>
		<category><![CDATA[Tooltip]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2518</guid>

					<description><![CDATA[<p>Multi-line tooltips are very easy to set up, once you know your way around a few undocumented hiccups.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-line-tooltips">Multi-line tooltips</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/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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/inactive-control-tooltips-event-chaining" rel="bookmark" title="Inactive Control Tooltips &amp; Event Chaining">Inactive Control Tooltips &amp; Event Chaining </a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part2" rel="bookmark" title="Explicit multi-threading in Matlab part 2">Explicit multi-threading in Matlab part 2 </a> <small>Matlab performance can be improved by employing .Net (C#, VB, F# or C++) threads. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I often use tooltips in my Matlab GUIs. They are a fantastically intuitive and unobtrusive visual helper for users to understand the GUI. In this blog, I have already posted several articles about how to tweak tooltip contents (<a target="_blank" href="/articles/spicing-up-matlab-uicontrol-tooltips/">here</a>, <a target="_blank" href="/articles/additional-uicontrol-tooltip-hacks/">here</a>, and <a target="_blank" href="/articles/inactive-control-tooltips-event-chaining/">here</a>). Today I would like to expand on one of the aspects that were already covered, namely that of multi-line tooltips.</p>
<h3 id="Basic">Basic multi-line tooltips</h3>
<p>The basic multi-line tooltip consists of a simple string that includes the newline character. for example:</p>
<pre lang='matlab'>set(hControl, 'TooltipString', ['this is line 1' 10 'and this is line 2'])</pre>
<p>Or better (platform independent):</p>
<pre lang='matlab'>set(hControl, 'TooltipString', sprintf('this is line 1\nand this is line 2'))</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="A simple multi-line tooltip string" src="https://undocumentedmatlab.com/images/tooltip_multi-line1.png" title="A simple multi-line tooltip string" width="120" /><figcaption class="wp-caption-text">A simple multi-line tooltip string</figcaption></figure></center><br />
As can be seen, this is very simple to set up. Unfortunately, the font cannot be customized. Which leads us to:</p>
<h3 id="HTML">HTML-rendered multi-line tooltips</h3>
<p>Tooltips, like most other Matlab controls, <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">supports HTML rendering</a>. This is a natural corollary of the fact that Java Swing, on which all Matlab controls are based, <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/tutorial/uiswing/components/html.html">automatically supports HTML</a>. All we need to do is to add &#8216;<code>&lt;HTML&gt;</code>&#8216; at the very beginning of our tooltip string, and then we can embed HTML tags within the rest of the string:</p>
<pre lang='matlab'>set(hControl, 'tooltipString', '<html><b>line #1</b><br /><i><font color="red">line#2</font></i></html>');</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Multi-line HTML'ed tooltip" src="https://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/html2.png" title="Multi-line HTML'ed tooltip" width="54" /><figcaption class="wp-caption-text">Multi-line HTML'ed tooltip</figcaption></figure></center><br />
And a more sophisticated example, used within my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14225-java-based-data-table">createTable utility</a> on the File Exchange:<br />
<center><figure style="width: 597px" class="wp-caption aligncenter"><img decoding="async" alt="A more complex multi-line HTML-based tooltip" src="https://undocumentedmatlab.com/images/table.png" title="A more complex multi-line HTML-based tooltip" width="597" /><figcaption class="wp-caption-text">A more complex multi-line HTML-based tooltip</figcaption></figure></center><br />
Note that there is no need to close the final HTML tags in the tooltip string, although it&#8217;s not an error to do so (as I have done above).</p>
<h3 id="Problem">The problem with formatted multi-line tooltip</h3>
<p>Unfortunately, none of these two methods work when we wish to display formatted multi-line tooltips. For example, suppose that we wish to display struct data in a tooltip:</p>
<pre lang='matlab'>
>> myData = struct('a',pi, 'b',-4, 'very_long_field_name','short txt')
myData =
                       a: 3.14159265358979
                       b: -4
    very_long_field_name: 'short txt'
>> myDataStr = evalc('disp(myData)');
>> set(hControl, 'TooltipString', myDataStr);
</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Badly-formatted multi-line tooltip" src="https://undocumentedmatlab.com/images/tooltip_multi-line2.png" title="Badly-formatted multi-line tooltip" width="200" /><figcaption class="wp-caption-text">Badly-formatted multi-line tooltip</figcaption></figure></center><br />
If we try to use HTML, the result looks even worse, because if the HTML-renderer detects a newline character embedded in the string, it simply uses the regular (non-HTML) renderer:</p>
<pre lang='matlab'>set(hControl, 'TooltipString', ['<html>' myDataStr '</html>'])</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Failure to parse a string using HTML" src="https://undocumentedmatlab.com/images/tooltip_multi-line3.png" title="Failure to parse a string using HTML" width="200" /><figcaption class="wp-caption-text">Failure to parse a string using HTML</figcaption></figure></center><br />
Even if we fix this by replacing all line-separators with &#8216;<code>&lt;br/&gt;</code>&#8216;, we still get a badly-formatted tooltip, because HTML ignores all white spaces:</p>
<pre lang='matlab'>
>> myDataStr2 = strrep(myDataStr, sprintf('\n'), '<br />');
>> set(hControl, 'TooltipString', ['<html>' myDataStr2 '</html>'])
</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Badly-formatted multi-line tooltip" src="https://undocumentedmatlab.com/images/tooltip_multi-line4.png" title="Badly-formatted multi-line tooltip" width="200" /><figcaption class="wp-caption-text">Badly-formatted multi-line tooltip</figcaption></figure></center><br />
(you can see that it&#8217;s HTML-formatted by the fact that the tooltip contents do not have internal margins like in the non-HTML tooltip above)</p>
<h3 id="Fixed-width">Fixed-width font multi-line tooltips</h3>
<p>We now recall the HTML <code>&lt;pre&gt;</code> tag, which tells HTML not to ignore white-spaces. In most web browsers, it also defaults to using a fixed-width font. Unfortunately, this is not the case here:</p>
<pre lang='matlab'>set(hControl, 'TooltipString', ['<html><pre>' myDataStr2])</pre>
<p><center><figure style="width: 240px" class="wp-caption aligncenter"><img decoding="async" alt="Still not quite right..." src="https://undocumentedmatlab.com/images/tooltip_multi-line5.png" title="Still not quite right..." width="240" /><figcaption class="wp-caption-text">Still not quite right...</figcaption></figure></center><br />
Which brings us to the final customization of the day, namely explicitly forcing the tooltip to use a fixed-width font:</p>
<pre lang='matlab'>set(hControl, 'TooltipString', ['<html><pre><font face="courier new">' myDataStr2 '</font>'])</pre>
<p><center><figure style="width: 320px" class="wp-caption aligncenter"><img decoding="async" alt="Finally - a well-formatted multi-line tooltip" src="https://undocumentedmatlab.com/images/tooltip_multi-line6.png" title="Finally - a well-formatted multi-line tooltip" width="320" /><figcaption class="wp-caption-text">Finally - a well-formatted multi-line tooltip</figcaption></figure></center><br />
Even more powerful customizations can be achieved using CSS rather than pure HTML. This will be discussed a future article.</html></html></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-line-tooltips">Multi-line tooltips</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/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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/inactive-control-tooltips-event-chaining" rel="bookmark" title="Inactive Control Tooltips &amp; Event Chaining">Inactive Control Tooltips &amp; Event Chaining </a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/explicit-multi-threading-in-matlab-part2" rel="bookmark" title="Explicit multi-threading in Matlab part 2">Explicit multi-threading in Matlab part 2 </a> <small>Matlab performance can be improved by employing .Net (C#, VB, F# or C++) threads. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/multi-line-tooltips/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
