<?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>Undocumented Matlab &#187; Icons</title> <atom:link href="http://undocumentedmatlab.com/blog/category/icons/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 02 Feb 2012 00:24:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>Uitab colors, icons and images</title><link>http://undocumentedmatlab.com/blog/uitab-colors-icons-images/</link> <comments>http://undocumentedmatlab.com/blog/uitab-colors-icons-images/#comments</comments> <pubDate>Wed, 10 Nov 2010 18:00:01 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[GUI]]></category> <category><![CDATA[Icons]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[HTML]]></category> <category><![CDATA[uitools]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1955</guid> <description><![CDATA[Matlab's semi-documented tab panels can be customized using some undocumented hacks<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uitab-customizations/' rel='bookmark' title='Uitab customizations'>Uitab customizations</a> <small>This article shows several customizations that can be done to Matlab's undocumented tab-panels functionality...</small></li><li><a
href='http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/' rel='bookmark' title='Tab panels &#8211; uitab and relatives'>Tab panels &#8211; uitab and relatives</a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-icons/' rel='bookmark' title='Setting system tray icons'>Setting system tray icons</a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uitable-cell-colors/' rel='bookmark' title='Uitable cell colors'>Uitable cell colors</a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A few months ago I published a post about <a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/">Matlab&#8217;s semi-documented tab-panel functionality</a>, where I promised a follow-up article on tab customizations. A reader of this blog <a
target="_blank" href="http://undocumentedmatlab.com/blog/customizing-uicontrol-border/#comment-21714">asked a related question</a> earlier today, so I decided it&#8217;s about time I fulfilled this promise.</p><p>As with most Matlab controls, the underlying Java component enables far greater customization than possible using plain Matlab. Today I will show three specific customizations. We start with a basic tab group, and get the underlying Java component:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Prevent an annoying warning msg</span>
<span style="color: #0000FF;">warning</span> off MATLAB<span style="color: #F0F;">:</span>uitabgroup<span style="color: #F0F;">:</span>OldVersion
&nbsp;
<span style="color: #228B22;">% Prepare a tab-group consisting of two tabs</span>
hTabGroup = uitabgroup; <span style="color: #0000FF;">drawnow</span>;
tab1 = uitab<span style="color: #080;">&#40;</span>hTabGroup, <span style="color:#A020F0;">'title'</span>,<span style="color:#A020F0;">'Panel 1'</span><span style="color: #080;">&#41;</span>;
a = <span style="color: #0000FF;">axes</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>, tab1<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">surf</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">peaks</span><span style="color: #080;">&#41;</span>;
tab2 = uitab<span style="color: #080;">&#40;</span>hTabGroup, <span style="color:#A020F0;">'title'</span>,<span style="color:#A020F0;">'Panel 2'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span>tab2, <span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">'Close'</span>, <span style="color:#A020F0;">'Callback'</span>,<span style="color:#A020F0;">'close(gcbf)'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Get the underlying Java reference (use hidden property)</span>
jTabGroup = <span style="color: #0000FF;">getappdata</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hTabGroup<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JTabbedPane'</span><span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Colors">Foreground &#038; background tab colors</h3><p>We can set the tab font color using <i>setForeground()</i> and <i>setForegroundAt()</i>, or via HTML. Note that <i>setForegroundAt()</i> overrides anything set by <i>setForeground()</i>. Also remember that Java uses 0-based indexing so tab #1 is actually the second tab:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Equivalent manners to set a red tab foreground:</span>
jTabGroup.<span style="">setForegroundAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,java.<span style="">awt</span>.<span style="">Color</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1.0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% tab #1</span>
jTabGroup.<span style="">setTitleAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color:#A020F0;">'&lt;html&gt;&lt;font color=&quot;red&quot;&gt;&lt;i&gt;Panel 2'</span><span style="color: #080;">&#41;</span>;
jTabGroup.<span style="">setForeground</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Color</span>.<span style="">red</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Unfortunately, the corresponding <i>setBackgroundAt(tabIndex,color)</i> method has no visible effect, and the Matlab-extended tabs keep their white/gray backgrounds. A similar attempt to modify the tab&#8217;s <b>BackgroundColor</b> property fails, since Matlab made this property unmodifiable (=&#8217;none&#8217;).  A simple solution is to use a <a
target="_blank" rel="nofollow" href="http://www.w3schools.com/css/css_background.asp">CSS background</a>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Equivalent manners to set a yellow tab background:</span>
jTabGroup.<span style="">setTitleAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'&lt;html&gt;&lt;div style=&quot;background:#ffff00;&quot;&gt;Panel 1'</span><span style="color: #080;">&#41;</span>;
jTabGroup.<span style="">setTitleAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'&lt;html&gt;&lt;div style=&quot;background:yellow;&quot;&gt;Panel 1'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 350px"><img
alt="uitabgroup with non-default forground and background tab colors and fonts" src="http://UndocumentedMatlab.com/images/uitabgroup5_bgcolor.png" title="uitabgroup with non-default forground and background tab colors and fonts" width="340" height="265" /><p
class="wp-caption-text"><i><b>uitabgroup</b></i> with non-default forground and background tab colors and fonts</p></div></center></p><p>We can set the foreground text color using the <a
target="_blank" rel="nofollow" href="http://www.w3schools.com/css/css_colors.asp">CSS <i>color</i> directive</a>. Similarly, we can also set a background gradient image for the tabs, using the CSS <i>background-image</i> directive. Which leads us to our next customization:</p><h3 id="Icons">Icon images</h3><p>Icons and sub-components can be added to the tabs. Unfortunately, for some reason that I do not fully understand, jTabGroup.<i>setIconAt()</i> has no apparent effect. The solution is to set our own custom control as the requested tab, and add our icon (or other customizations) to it. Here is a simple example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Add an icon to tab #1 (=second tab)</span>
icon = javax.<span style="">swing</span>.<span style="">ImageIcon</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'C:\Yair\save.gif'</span><span style="color: #080;">&#41;</span>;
jLabel = javax.<span style="">swing</span>.<span style="">JLabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tab #2'</span><span style="color: #080;">&#41;</span>;
jLabel.<span style="">setIcon</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
jTabGroup.<span style="">setTabComponentAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,jLabel<span style="color: #080;">&#41;</span>;	<span style="color: #228B22;">% Tab #1 = second tab</span>
&nbsp;
<span style="color: #228B22;">% Note: icon is automatically grayed when label is disabled</span>
jLabel.<span style="">setEnabled</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
jTabGroup.<span style="">setEnabledAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% disable only tab #1</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 302px"><img
alt="tab with a custom icon (enabled)" src="http://UndocumentedMatlab.com/images/uitabgroup6_icon.png" title="tab with a custom icon (enabled)" width="292" height="159" /><br/><img
alt="tab with a custom icon (enabled)" src="http://UndocumentedMatlab.com/images/uitabgroup6_icon2.png" title="tab with a custom icon (disabled)" width="292" height="159" /><p
class="wp-caption-text">tab with a custom icon (enabled &#038; disabled)</p></div></center></p><h3 id="Buttons">Close buttons</h3><p>Now let&#8217;s try a more complex example, of adding a close (&#8216;x&#8217;) button to one of the tabs. Generalizing this code snippet is left as an exercise to the reader:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% First let's load the close icon</span>
jarFile = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/java/jar/mwt.jar'</span><span style="color: #080;">&#41;</span>;
iconsFolder = <span style="color:#A020F0;">'/com/mathworks/mwt/resources/'</span>;
iconURI = <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'jar:file:/'</span> jarFile <span style="color:#A020F0;">'!'</span> iconsFolder <span style="color:#A020F0;">'closebox.gif'</span><span style="color: #080;">&#93;</span>;
icon = javax.<span style="">swing</span>.<span style="">ImageIcon</span><span style="color: #080;">&#40;</span>java.<span style="">net</span>.<span style="">URL</span><span style="color: #080;">&#40;</span>iconURI<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Now let's prepare the close button: icon, size and callback</span>
jCloseButton = handle<span style="color: #080;">&#40;</span>javax.<span style="">swing</span>.<span style="">JButton</span>,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
jCloseButton.<span style="">setIcon</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
jCloseButton.<span style="">setPreferredSize</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Dimension</span><span style="color: #080;">&#40;</span><span style="color: #33f;">15</span>,<span style="color: #33f;">15</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
jCloseButton.<span style="">setMaximumSize</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Dimension</span><span style="color: #080;">&#40;</span><span style="color: #33f;">15</span>,<span style="color: #33f;">15</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
jCloseButton.<span style="">setSize</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Dimension</span><span style="color: #080;">&#40;</span><span style="color: #33f;">15</span>,<span style="color: #33f;">15</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jCloseButton, <span style="color:#A020F0;">'ActionPerformedCallback'</span>,@<span style="color: #080;">&#40;</span>h,e<span style="color: #080;">&#41;</span><span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>tab2<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Now let's prepare a tab panel with our label and close button</span>
jPanel = javax.<span style="">swing</span>.<span style="">JPanel</span>;	<span style="color: #228B22;">% default layout = FlowLayout</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jPanel.<span style="">getLayout</span>, <span style="color:#A020F0;">'Hgap'</span>,<span style="color: #33f;">0</span>, <span style="color:#A020F0;">'Vgap'</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% default gap = 5px</span>
jLabel = javax.<span style="">swing</span>.<span style="">JLabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tab #2'</span><span style="color: #080;">&#41;</span>;
jPanel.<span style="">add</span><span style="color: #080;">&#40;</span>jLabel<span style="color: #080;">&#41;</span>;
jPanel.<span style="">add</span><span style="color: #080;">&#40;</span>jCloseButton<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Now attach this tab panel as the tab-group's 2nd component</span>
jTabGroup.<span style="">setTabComponentAt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,jPanel<span style="color: #080;">&#41;</span>;	<span style="color: #228B22;">% Tab #1 = second tab</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 369px"><img
alt="tab with an attached close button" src="http://UndocumentedMatlab.com/images/uitabgroup8_close_button.png" title="tab with an attached close button" width="359" height="185" /><p
class="wp-caption-text">tab with an attached close button</p></div></center></p><p>Next week&#8217;s article will conclude the series on Matlab&#8217;s <i><b>uitab</b></i>. Any particular customization you are interested in? Please do post a <a
target="_blank" href="http://undocumentedmatlab.com/blog/uitab-colors-icons-images/#respond">comment</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uitab-customizations/' rel='bookmark' title='Uitab customizations'>Uitab customizations</a> <small>This article shows several customizations that can be done to Matlab's undocumented tab-panels functionality...</small></li><li><a
href='http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/' rel='bookmark' title='Tab panels &#8211; uitab and relatives'>Tab panels &#8211; uitab and relatives</a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-icons/' rel='bookmark' title='Setting system tray icons'>Setting system tray icons</a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uitable-cell-colors/' rel='bookmark' title='Uitable cell colors'>Uitable cell colors</a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/uitab-colors-icons-images/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Figure toolbar components</title><link>http://undocumentedmatlab.com/blog/figure-toolbar-components/</link> <comments>http://undocumentedmatlab.com/blog/figure-toolbar-components/#comments</comments> <pubDate>Thu, 27 Aug 2009 16:31:36 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Icons]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Toolbar]]></category> <category><![CDATA[uitools]]></category> <category><![CDATA[uiundo]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=541</guid> <description><![CDATA[Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-side-effect-removing-figure-toolbar/' rel='bookmark' title='uicontrol side-effect: removing figure toolbar'>uicontrol side-effect: removing figure toolbar</a> <small>Matlab's built-in uicontrol function has a side-effect of removing the figure toolbar. This was undocumented until lately. This article describes the side-effect behavior and how to fix it....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Toolbars are by now a staple of modern GUI design. An unobtrusive list of small icons enables easy access to multiple application actions without requiring large space for textual descriptions. Unfortunately, the built-in documented support for the Matlab toolbars is limited to adding icon buttons via the <b><i>uipushtool</i></b> and <b><i>uitoggletool</i></b> functions, and new toolbars containing them via the <b><i>uitoolbar</i></b> function. In this post I will introduce several additional customizations that rely on undocumented features.</p><p>This article will only describe figure toolbars. However, much of the discussion is also relevant to the desktop (Command Window) toolbars and interested users can adapt it accordingly.</p><h3 id="Matlab">Accessing toolbar buttons &#8211; undo/redo</h3><p>Let&#8217;s start by adding undo/redo buttons to the existing figure toolbar. I am unclear why such an elementary feature was not included in the default figure toolbar, but this is a fact that can easily be remedied. In <a
target="_blank" href="http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/">another post</a> I describe <b><i>uiundo</i></b>, Matlab&#8217;s semi-documented support for undo/redo functionality, but for the present let&#8217;s assume we already have this functionality set up.</p><p>First, let&#8217;s prepare our icons, which are basically a green-filled triangle icon and its mirror image:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Load the Redo icon</span>
icon = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/toolbox/matlab/icons/greenarrowicon.gif'</span><span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>cdata,map<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">imread</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Convert white pixels into a transparent background</span>
map<span style="color: #080;">&#40;</span><span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>==<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> = <span style="color: #0000FF;">NaN</span>;
&nbsp;
<span style="color: #228B22;">% Convert into 3D RGB-space</span>
cdataRedo = ind2rgb<span style="color: #080;">&#40;</span>cdata,map<span style="color: #080;">&#41;</span>;
cdataUndo = cdataRedo<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">16</span><span style="color: #F0F;">:</span>-<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Now let&#8217;s add these icons to the default figure toolbar:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Add the icon (and its mirror image = undo) to the latest toolbar</span>
hUndo = uipushtool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'cdata'</span>,cdataUndo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'undo'</span>, <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execUndo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
hRedo = uipushtool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'redo'</span>, <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execRedo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 306px"><img
alt="Undo/redo buttons" src="http://UndocumentedMatlab.com/images/uiundo4.png" title="Undo/redo buttons" width="296" height="199" /><p
class="wp-caption-text">Undo/redo buttons</p></div></center></p><p>In the preceding screenshot, since no figure toolbar was previously shown, <b><i>uipushtool</i></b> added the undo and redo buttons to a new toolbar. Had the figure toolbar been visible, then the buttons would have been added to its right end. Since undo/redo buttons are normally requested near the left end of toolbars, we need to rearrange the toolbar buttons:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hToolbar = findall<span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'FigureToolBar'</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">%hToolbar = get(hUndo,'Parent');  % an alternative</span>
hButtons = findall<span style="color: #080;">&#40;</span>hToolbar<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'children'</span>,hButtons<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">4</span><span style="color: #F0F;">:</span>end-<span style="color: #33f;">4</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,end-<span style="color: #33f;">3</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo,<span style="color:#A020F0;">'Separator'</span>,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 312px"><img
alt="Undo/redo buttons in their expected positions" src="http://UndocumentedMatlab.com/images/uiundo5.png" title="Undo/redo buttons in their expected positions" width="302" height="199" /><p
class="wp-caption-text">Undo/redo buttons in their expected positions</p></div></center></p><p>We would normally preserve hUndo and hRedo, and modify their <i>Tooltip</i> and <i>Visible</i>/<i>Enable</i> properties in run-time, based on the availability and name of the latest undo/redo actions:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Retrieve redo/undo object</span>
undoObj = <span style="color: #0000FF;">getappdata</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'uitools_FigureToolManager'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>undoObj<span style="color: #080;">&#41;</span>
   undoObj = uitools.<span style="">FigureToolManager</span><span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'uitools_FigureToolManager'</span>,undoObj<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Customize the toolbar buttons</span>
latestUndoAction = undoObj.<span style="">CommandManager</span>.<span style="">peekundo</span>;
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>latestUndoAction<span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo, <span style="color:#A020F0;">'Tooltip'</span>,<span style="color:#A020F0;">''</span>, <span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">else</span>
   tooltipStr = <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'undo'</span> latestUndoAction.<span style="">Name</span><span style="color: #080;">&#93;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo, <span style="color:#A020F0;">'Tooltip'</span>,tooltipStr, <span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>We can easily adapt the method I have just shown to modify/update existing toolbar icons: hiding/disabling them etc. based on the application needs at run-time.</p><h3 id="Java">Adding non-button toolbar components &#8211; undo dropdown</h3><p>A more advanced customization is required if we wish to present the undo/redo actions in a drop-down (combo-box). Unfortunately, since Matlab only enables adding <b><i>uipushtool</i></b>s and <b><i>uitoggletool</i></b>s to toolbars, we need to use a Java component. The drawback of using such a component is that it is inaccessible via the toolbar&#8217;s Children property (implementation of the drop-down callback function is left as an exercise to the reader):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Add undo dropdown list to the toolbar</span>
jToolbar = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'ComponentPeer'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>jToolbar<span style="color: #080;">&#41;</span>
   undoActions = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>undoObj.<span style="">CommandManager</span>.<span style="">UndoStack</span>,<span style="color:#A020F0;">'Name'</span><span style="color: #080;">&#41;</span>;
   jCombo = javax.<span style="">swing</span>.<span style="">JComboBox</span><span style="color: #080;">&#40;</span>undoActions<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #F0F;">:</span>-<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jCombo, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, @myUndoCallbackFcn<span style="color: #080;">&#41;</span>;
   jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">add</span><span style="color: #080;">&#40;</span>jCombo,<span style="color: #33f;">5</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%5th position, after printer icon</span>
   jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">repaint</span>;
   jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">revalidate</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Drop-down (combo-box) callback function</span>
<span style="color: #0000FF;">function</span> myUndoCallbackFcn<span style="color: #080;">&#40;</span>hCombo,hEvent<span style="color: #080;">&#41;</span>
   itemIndex = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hCombo,<span style="color:#A020F0;">'SelectedIndex'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% 0=topmost item</span>
   itemName  = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hCombo,<span style="color:#A020F0;">'SelectedItem'</span><span style="color: #080;">&#41;</span>;
   <span style="color: #228B22;">% user processing needs to be placed here</span>
<span style="color: #0000FF;">end</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 392px"><img
alt="Undo dropdown list" src="http://UndocumentedMatlab.com/images/uiundo6.png" title="Undo dropdown list" width="382" height="221" /><p
class="wp-caption-text">Undo dropdown list</p></div></center></p><p>Note that the javax.swing.JComboBox constructor accepts a cell-array of strings (undoActions in the snippet above). A user-defined dropdownlist might be constructed as follows (also see a <a
rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/160674#405575">related CSSM thread</a>):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #F0F;">...</span>
<span style="">dropdownStrings</span> = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'here'</span>, <span style="color:#A020F0;">'there'</span>, <span style="color:#A020F0;">'everywhere'</span><span style="color: #080;">&#125;</span>;
jCombo = javax.<span style="">swing</span>.<span style="">JComboBox</span><span style="color: #080;">&#40;</span>dropdownStrings<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jCombo, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, @myUndoCallbackFcn<span style="color: #080;">&#41;</span>;
jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">addSeparator</span>;
jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">add</span><span style="color: #080;">&#40;</span>jCombo<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% at end, following a separator mark</span>
jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">repaint</span>;
jToolbar<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">revalidate</span>;
<span style="color: #F0F;">...</span></pre></div></div><p>A similar approach can be used to add checkboxes, radio-buttons and other non-button controls.</p><p>In next week&#8217;s post I will describe how the toolbar can be customized using undocumented functionality to achieve a non-default background, a floating toolbar (&#8220;palette&#8221;) effect and other interesting customizations. If you have any specific toolbar-related request, I&#8217;ll be happy to hear in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-side-effect-removing-figure-toolbar/' rel='bookmark' title='uicontrol side-effect: removing figure toolbar'>uicontrol side-effect: removing figure toolbar</a> <small>Matlab's built-in uicontrol function has a side-effect of removing the figure toolbar. This was undocumented until lately. This article describes the side-effect behavior and how to fix it....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/figure-toolbar-components/feed/</wfw:commentRss> <slash:comments>25</slash:comments> </item> <item><title>Setting system tray popup messages</title><link>http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/</link> <comments>http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/#comments</comments> <pubDate>Tue, 31 Mar 2009 23:09:25 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Desktop]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Icons]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=130</guid> <description><![CDATA[System-tray icons and messages can be programmatically set and controlled from within Matlab, using new functionality available since R2007b.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-icons/' rel='bookmark' title='Setting system tray icons'>Setting system tray icons</a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-text/' rel='bookmark' title='Setting status-bar text'>Setting status-bar text</a> <small>The Matlab desktop and figure windows have a usable statusbar which can only be set using undocumented methods. This post shows how to set the status-bar text....</small></li><li><a
href='http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/' rel='bookmark' title='Changing system preferences programmatically'>Changing system preferences programmatically</a> <small>Matlab user/system preferences can be changed programmatically, from within your Matlab application or from the Matlab desktop command prompt. This post details how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-help-popup-contents/' rel='bookmark' title='Customizing help popup contents'>Customizing help popup contents</a> <small>The built-in HelpPopup, available since Matlab R2007b, has a back-door that enables displaying arbitrary text, HTML and URL web-pages....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Continuing my previous post about <a
href="http://undocumentedmatlab.com/blog/setting-system-tray-icons/" target="_blank">setting system-tray icons</a>, I will now show how to set informational popup messages next to these icons.</p><p>Asynchronous informational messages can be presented next to the sys-tray icon, in a fashion similar to what we came to expect from modern programs. This could be used to indicate some unexpected event that was detected, or the end of a complex calculation phase. The message title, text and severity icon are all customizable.</p><p>Unfortunately, the Java method used to display messages, java.awt.TrayIcon.displayMessage(), expects an object of type java.awt.TrayIcon.MessageType, which is an enumeration within the TrayIcon class. However, Matlab&#8217;s dot-notation does not recognize what should have been the following correct notation, so we need to resort to Java reflection:</p><blockquote><pre><span style="color: #000000;">&gt;&gt; trayIcon.displayMessage(</span><span style="color: #800080;">'title'</span>,<span style="color: #800080;">'info msg'</span><span style="color: #000000;">,TrayIcon.MessageType.INFO);</span>
<span style="color: #ff0000;">??? No appropriate method or public field MessageType for class java.awt.TrayIcon</span>

<span style="color: #000000;">&gt;&gt; trayIconClasses = trayIcon.getClass.getClasses;
&gt;&gt; trayIconClasses(1)</span>
ans =
class java.awt.TrayIcon$MessageType	&lt;= hurray!!!
<span style="color: #000000;">&gt;&gt; MessageTypes = trayIconClasses(1).getEnumConstants</span>
MessageTypes =
java.awt.TrayIcon$MessageType[]:
    [java.awt.TrayIcon$MessageType]	&lt;= 1: ERROR
    [java.awt.TrayIcon$MessageType]	&lt;= 2: WARNING
    [java.awt.TrayIcon$MessageType]	&lt;= 3: INFO
    [java.awt.TrayIcon$MessageType]	&lt;= 4: NONE
<span style="color: #000000;">&gt;&gt; trayIcon.displayMessage(</span><span style="color: #800080;">'title'</span>,<span style="color: #800080;">'info msg'</span><span style="color: #000000;">,MessageTypes(3));</span>
</pre></blockquote><p><center><img
src="http://undocumentedmatlab.com/images/systray1.png" alt="systray INFO message" title="systray INFO message" /></center></p><p>and another example, now with a WARNING icon:<br
/><center><img
src="http://undocumentedmatlab.com/images/systray2.png" alt="systray WARNING message" title="systray WARNING message" /></center></p><p>If the title string is left empty, then neither title nor the severity icon will be displayed. The message can still be manually dismissed by clicking within its boundaries:<br
/><center><br
/> <img
src="http://undocumentedmatlab.com/images/systray4.png" alt="systray messages without a title (hence also without a severity icon)" title="systray messages without a title (hence also without a severity icon)" /><br
/> <img
src="http://undocumentedmatlab.com/images/systray7.png" alt="systray messages without a title (hence also without a severity icon)" title="systray messages without a title (hence also without a severity icon)" /><br
/></center></p><p>Informational popup messages are automatically aligned and positioned by the system. Messages are automatically dismissed by the system after some time, if not dismissed by the user first. The exact time is determined by system and user activity and other such external factors. Informational messages replace one another, if the previous message has still not been cleared by the user.</p><p>I have created a utility function called SYSTRAY, which is a convenience function that facilitates the setup and update of system tray icons and messages. SYSTRAY (with source code) can be <a
rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23299" target="_blank">downloaded from the File Exchange</a>.</p><p>I would be happy to hear if and how you&#8217;re using the new system-tray functionality in your application &#8211; let me know below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-icons/' rel='bookmark' title='Setting system tray icons'>Setting system tray icons</a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-text/' rel='bookmark' title='Setting status-bar text'>Setting status-bar text</a> <small>The Matlab desktop and figure windows have a usable statusbar which can only be set using undocumented methods. This post shows how to set the status-bar text....</small></li><li><a
href='http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/' rel='bookmark' title='Changing system preferences programmatically'>Changing system preferences programmatically</a> <small>Matlab user/system preferences can be changed programmatically, from within your Matlab application or from the Matlab desktop command prompt. This post details how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-help-popup-contents/' rel='bookmark' title='Customizing help popup contents'>Customizing help popup contents</a> <small>The built-in HelpPopup, available since Matlab R2007b, has a back-door that enables displaying arbitrary text, HTML and URL web-pages....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>Setting system tray icons</title><link>http://undocumentedmatlab.com/blog/setting-system-tray-icons/</link> <comments>http://undocumentedmatlab.com/blog/setting-system-tray-icons/#comments</comments> <pubDate>Tue, 24 Mar 2009 20:47:54 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Desktop]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Icons]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=67</guid> <description><![CDATA[System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/' rel='bookmark' title='Setting system tray popup messages'>Setting system tray popup messages</a> <small>System-tray icons and messages can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/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='http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/' rel='bookmark' title='Changing system preferences programmatically'>Changing system preferences programmatically</a> <small>Matlab user/system preferences can be changed programmatically, from within your Matlab application or from the Matlab desktop command prompt. This post details how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/' rel='bookmark' title='Setting listbox mouse actions'>Setting listbox mouse actions</a> <small>Matlab listbox uicontrol can be modified to detect mouse events for right-click context menus, dynamic tooltips etc....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Java 1.6, included in Matlab releases since Matlab 7.5 (R2007b), enables programmatic access to system tray icons on such systems that support this functionality (Windows, Linux and possibly others).  If the SystemTray object indicates that it <em>isSupported()</em>, then a TrayIcon can be added, along with an associated tooltip and popup menu:</p><blockquote><pre>sysTray = java.awt.SystemTray.getSystemTray;
if (sysTray.isSupported)
   myIcon = fullfile(matlabroot,<span style="color: #800080;">'/toolbox/matlab/icons/matlabicon.gif'</span>);
   iconImage = java.awt.Toolkit.getDefaultToolkit.createImage(myIcon);
   trayIcon = java.awt.TrayIcon(iconImage, <span style="color: #800080;">'initial tooltip'</span>);
   trayIcon.setToolTip(<span style="color: #800080;">'click this icon for applicative context menu'</span>);
end</pre></blockquote><p><center><div
id="attachment_68" class="wp-caption aligncenter" style="width: 219px"><img
class="size-full wp-image-68" title="sample system tray icon" src="http://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/systray5.png" alt="sample system tray icon" width="209" height="40" /><p
class="wp-caption-text">sample system tray icon</p></div></center></p><p>The icon image can be made to automatically resize to the system-tray dimensions, using the trayIcon.<em>setImageAutoSize(true)</em> method (by default the icon image will maintain its original size, getting cropped or appearing small as the case may be).</p><p>Of course, after initial setup, all the sys-tray icon&#8217;s properties (icon image, popup, tooltip etc.) can be modified with convenient set methods (<em>setImage(), setPopupMenu(), setTooltip()</em>) or via Matlab&#8217;s <em>set()</em> function.</p><p>Icon popup menus are very similar in concept to Matlab uicontextmenus. Unfortunately, they need to be programmed separately since Java does not accept uicontextmenu handles. This is actually quite easy, as the following code snippet shows:</p><blockquote><pre><span style="color: #008000;">% Prepare the context menu
</span>menuItem1 = java.awt.MenuItem(<span style="color: #800080;">'action #1'</span>);
menuItem2 = java.awt.MenuItem(<span style="color: #800080;">'action #2'</span>);
menuItem3 = java.awt.MenuItem(<span style="color: #800080;">'action #3'</span>);

<span style="color: #008000;">% Set the menu items' callbacks</span>
set(menuItem1,<span style="color: #800080;">'ActionPerformedCallback'</span>,@myFunc1);
set(menuItem2,<span style="color: #800080;">'ActionPerformedCallback'</span>,{@myfunc2,data1,data2});
set(menuItem3,<span style="color: #800080;">'ActionPerformedCallback'</span>,<span style="color: #800080;">'disp(''action #3...'')'</span>);

<span style="color: #008000;">% Disable one of the menu items</span>
menuItem2.setEnabled(0);        <span style="color: #008000;">% or: set(menuItem2,'Enabled','off');</span>

<span style="color: #008000;">% Add all menu items to the context menu (with internal </span><span style="color: #008000;">separator)
</span>jmenu = java.awt.PopupMenu;
jmenu.add(menuItem1);
jmenu.add(menuItem2);
jmenu.addSeparator;
jmenu.add(menuItem3);

<span style="color: #008000;">% Finally, attach the context menu to the icon</span>
trayIcon.setPopupMenu(jmenu);    <span style="color: #008000;">% or: set(trayIcon,'PopupMenu',jmenu);</span></pre></blockquote><p><center><div
id="attachment_69" class="wp-caption aligncenter" style="width: 118px"><img
class="size-full wp-image-69" title="Tray icon context (right-click) menu" src="http://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/systray3.png" alt="Tray icon context (right-click) menu" width="108" height="98" /><p
class="wp-caption-text">Tray icon context (right-click) menu</p></div></center></p><p>Unfortunately, neither the icon tooltip nor its popup menu supports HTML. The reason is that SystemTray is actually not part of Swing at all. The system-tray functionality resides in the java.awt package, and does not inherit <a
href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">javax.swing.JLabel&#8217;s (and Matlab uicontrols) support for HTML</a>.</p><p>I have created a utility function called SYSTRAY, which is a convenience function that facilitates the setup and update of system tray icons. <a
href="http://www.mathworks.com/matlabcentral/fileexchange/23299" target="_blank" rel="nofollow">SYSTRAY (with source code) can be downloaded from the File Exchange</a>.</p><p>In <a
href="http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/" target="_blank">a separate post</a>, I shall detail how informational pop-up messages can be attached to system-tray icons. This requires a bit of Java-hacking, so is beyond the scope of a single blog post.</p><p>Please note the new <a
href="http://undocumentedmatlab.com/todo/" target="_blank">TODO page</a>, which details my future posts. I would be happy to hear your requests for new topics, or telling me which topics you&#8217;d like to see earlier than others.</p><p><strong><u>Addendum (May 15, 2009)</u>: A kind reader today left a comment on <a
target="_noblank" href="http://undocumentedmatlab.com/blog/uisplitpane/comment-page-1/#comment-658">another post of this blog</a> with a solution for some reported Java exceptions when using systray in Matlab R2008b onward.</strong></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/' rel='bookmark' title='Setting system tray popup messages'>Setting system tray popup messages</a> <small>System-tray icons and messages can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li><li><a
href='http://undocumentedmatlab.com/blog/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='http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/' rel='bookmark' title='Changing system preferences programmatically'>Changing system preferences programmatically</a> <small>Matlab user/system preferences can be changed programmatically, from within your Matlab application or from the Matlab desktop command prompt. This post details how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/' rel='bookmark' title='Setting listbox mouse actions'>Setting listbox mouse actions</a> <small>Matlab listbox uicontrol can be modified to detect mouse events for right-click context menus, dynamic tooltips etc....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-system-tray-icons/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           category
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-04 03:32:52 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/category/icons/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      1.236s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328351572; expires=Sun, 03-Feb-2013 10:32:52 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:32:52 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:32:52 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               af31f8f7b3509ab4612ac5f975613f9e
Content-Encoding:   gzip
-->
