<?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; JavaFrame</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/javaframe/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>Docking figures in compiled applications</title><link>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/</link> <comments>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#comments</comments> <pubDate>Wed, 15 Jun 2011 18:00:56 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Compiler]]></category> <category><![CDATA[Docking]]></category> <category><![CDATA[Figure]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2341</guid> <description><![CDATA[Figures in compiled applications cannot officially be docked since R2008a, but this can be done using a simple undocumented trick.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;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='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/jmi-wrapper-local-matlabcontrol-part-2/' rel='bookmark' title='JMI wrapper &#8211; local MatlabControl part 2'>JMI wrapper &#8211; local MatlabControl part 2</a> <small>An example using matlabcontrol for calling Matlab from within a Java class is explained and discussed...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Up until Matlab release R2008a, the Matlab compiler enabled compiled Matlab applications to have dockable figure windows, which docked into a &#8220;Figures&#8221; container. <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-A6XFET/">Starting with R2008a</a>, the compiler removed the figure&#8217;s docking capability and figures can no longer be docked.</p><p>Well, at least not officially <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p>The following trick restores the docking controls to figures in R2008a-compiled applications, enabling figure docking. Simply add one or both of the following alternatives in your application, after the figure has been created:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternative #1 - uses pure Matlab</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'DockControls'</span>, <span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative #2 - uses the underlying Java frame</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">try</span>
   <span style="color: #228B22;">% This works up to R2011a</span>
   jFrame.<span style="">fFigureClient</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #228B22;">% This works from R2008b and up</span>
   jFrame.<span style="">fHG1Client</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>where <code>hFig</code> is the figure handle. This will have no effect for the regular interpreted (non-compiled) run of the application, where these controls are &#8216;on&#8217; by default. But in the compiled application, although it may erroneously report that the controls are &#8216;on&#8217;, they are in fact &#8216;off&#8217;, so turning them &#8216;on&#8217; fixes the problem.</p><p><center><div
class="wp-caption aligncenter" style="width: 478px"><img
alt="Matlab figure docking control" src="http://UndocumentedMatlab.com/images/dock4.png" title="Matlab figure docking control" width="468" /><p
class="wp-caption-text">Matlab figure docking control</p></div></center></p><p><u>Note</u>: the two variants in alternative #2 above are actually identical, it is simply that the relevant field name has changed: Up to R2008a, only the <code>fFigureClient</code> existed; in R2008b, the <code>fHG1Client</code> field was added, which was simply an alias for <code>fFigureClient</code>, holding the same reference handle, so either of these fields could be used (a corresponding fHG2Client was also added &#8211; more on HG1 and HG2 <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/hg2/">here</a>). In R2011b (at least the pre-release), the <code>fFigureClient</code> alias field was dropped and only <code>fHG1Client</code> remained. While the field name has changed, the underlying docking functionality appears to have remained stable over all these releases. For the record, in answer to a <a
href="http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#comment-48632">user question below</a>, these fields can be listed using the built in <i><b>fieldnames</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% R2008b - R2011a:</span>
&gt;&gt; <span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span>jFrame<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
    <span style="color:#A020F0;">'fFigureClient'</span>
    <span style="color:#A020F0;">'fHG2Client'</span>
    <span style="color:#A020F0;">'fHG1Client'</span>
    <span style="color:#A020F0;">'fUseHG2'</span>
    <span style="color:#A020F0;">'UICONTROLBACKGROUND_OS'</span>
    <span style="color:#A020F0;">'UICONTROLBACKGROUND_COMPATIBLE'</span></pre></div></div><p>I was reminded of this trick by <a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/#comment-47197">Aurélien&#8217;s recent comment</a>, where he mentions MathWorks so-called workaround for this problem, which (IMHO) is really not a work-around at all: MathWorks advises to modify our application to use &#8211; would you believe this &#8211; tabbed panels to &#8220;dock&#8221; the separate figures contents onto separate panels. Not to mention the fact that this so-called &#8220;solution&#8221; relies on undocumented and unsupported Matlab functionality (that of <a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/">tabbed-panels</a>) and requires major rework of existing applications, it also results in far inferior look-and-feel than simple docking as G-d intended&#8230;</p><p>Since I have demonstrated above that the docking functionality actually exists in compiled apps just as in the interpreted m-file apps, I do not understand why MathWorks took such great pains to prevent this important functionality in the compiler. There must be some important reason for this, but I cannot think of any. Perhaps if there is enough public demand, MathWorks will agree to return the docking functionality.</p><p>Unfortunately, I recently discovered that in the most recent compiler, that ships with R2011a, alternative #1 above (which uses pure Matlab) no longer works. Sometime between R2008a and R2011a MathWorks discovered my first back-door and closed it. Such a pity&#8230;</p><p>Luckily, alternative #2 (which uses the underlying Java frame object) seems to still work, even on R2011a.</p><p>I still haven&#8217;t tested this on R2011b&#8217;s compiler (whose pre-release has become available for download yesterday), but hopefully the trick above will continue to work on R2011b and on subsequent releases &#8211; please <a
href="http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#respond">tell me</a> if you find out otherwise.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;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='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/jmi-wrapper-local-matlabcontrol-part-2/' rel='bookmark' title='JMI wrapper &#8211; local MatlabControl part 2'>JMI wrapper &#8211; local MatlabControl part 2</a> <small>An example using matlabcontrol for calling Matlab from within a Java class is explained and discussed...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>Minimize/maximize figure window</title><link>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#comments</comments> <pubDate>Wed, 18 May 2011 23:08:07 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2310</guid> <description><![CDATA[Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Over the past couple of years, I posted <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/javaframe/">several articles</a> using the <b>JavaFrame</b> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object. Today, I show how using <b>JavaFrame</b> we can solve a very frequent user request on the Matlab CSSM forum.</p><h3 id="Problem">The problem</h3><p>Matlab figures can be maximized, minimized and restored by <em>interactively</em> clicking the corresponding icon (or menu item) on the figure window&#8217;s frame (the title bar). However, we often need to create maximized main-application windows, and wish to save the users the need to manually maximize the window. Moreover, we may sometimes even wish to prevent users from resizing a maximized main window.</p><p>Unfortunately, Matlab does not contain any documented or supported way to <em>programmatically</em> maximize, minimize or restore a figure window.</p><p>This is very strange considering the fact that these are such elementary figure operations. Moreover, these operations are supported internally (and have been for many releases already), as shown below. It is therefore difficult for me to understand why they were not added to the documented Matlab HG wrapper functionality a long time ago. I fail to understand why obscure features such as docking were added to the wrapper, but standard minimization and maximization were not.</p><h3 id="Maximization">Maximization</h3><p><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/?term=maximize+window">Several solutions</a> have been presented to this problem over the years. Let us start with the pressing question of figure maximization:</p><p>Solutions that rely on documented Matlab features tend to compute the available screen size and resize the figure accordingly. The result is lacking in many respects: it does not account for the taskbar (neither in size nor in location, which is not necessarily at the bottom of the screen); it does not remove the window border as in regular maximized figures; and it often ignores extended desktops (i.e. an attached additional monitor).</p><p>The solutions that do work properly all rely on undocumented features: Some use platform-specific native Windows API in a mex-file (Jan Simon&#8217;s recent <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi">WindowAPI</a> submission really pushes the limit in this and other regards). Alternately, we can easily use the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>
jFrame =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigurePeer</span>@cdbd96
&nbsp;
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to maximize the figure</span>
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-maximize the figure</span></pre></div></div><h3 id="Minimization">Minimization</h3><p>To the best of my knowledge, there are no solutions for minimizing figure windows that use documented Matlab features. Again, this can be done using either native Windows API, or the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to minimize the figure</span>
&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-minimize the figure</span></pre></div></div><h3 id="Notes">Usage notes</h3><p><b>Maximized</b> and <b>Minimized</b> are mutually-exclusive, meaning that no more than one of them can be 1 (or true) at any time. This is automatically handled – users only need to be aware that a situation in which a window is both maximized and minimized at the same time is impossible (duh!).</p><p>There are several equivalent manners of setting <code>jFrame</code>&#8216;s <b>Maximized</b> and <b>Minimized</b> property values, and your choice may simply be a matter of aesthetics and personal taste:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Three alternative possibilities of setting Maximized:</span>
jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Maximized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% note interchangeable 1&lt; =&gt;true, 0&lt; =&gt;false</span>
jFrame.<span style="">handle</span>.<span style="">Maximized</span> = <span style="color: #33f;">1</span>;</pre></div></div><p><code>jFrame</code> follows Java convention: the accessor method that retrieves boolean values is called <i>is&lt;Propname&gt;()</i> instead of <i>get&lt;Propname&gt;</i>. In our case: <i>isMaximized()</i> and <i>isMinimized()</i>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">flag</span> = jFrame.<span style="">isMinimized</span>;        <span style="color: #228B22;">% Note: isMinimized, not getMinimized</span>
<span style="color: #0000FF;">flag</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Minimized'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">flag</span> = jFrame.<span style="">handle</span>.<span style="">Minimized</span>;</pre></div></div><p>In some old Matlab releases, <code>jFrame</code> did not possess the <b>Maximized</b> and <b>Minimized</b> properties, and their associated accessor methods. In this case, use the internal <code>FrameProxy</code> which has always contained them:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrameProxy = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> 
jFrameProxy =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigureFrameProxy</span>$FigureFrame<span style="color: #080;">&#91;</span>fClientProxyFrame,<span style="color: #33f;">227</span>,<span style="color: #33f;">25</span>,568x502,invalid,layout=java.<span style="">awt</span>.<span style="">BorderLayout</span>,<span style="color: #0000FF;">title</span>=<span style="color: #0000FF;">Figure</span> <span style="color: #33f;">1</span>,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,<span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; <span style="color: #228B22;">% Three alternative possibilities of setting Minimized:</span>
&gt;&gt; jFrameProxy.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrameProxy,<span style="color:#A020F0;">'Minimized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; jFrameProxy.<span style="">handle</span>.<span style="">Minimized</span> = <span style="color: #0000FF;">true</span>;</pre></div></div><p>Using <code>FrameProxy</code> for figure minimization and maximization works correctly on both old and new Matlab releases; using <code>jFrame</code> is slightly simpler but only works on recent Matlab releases. Depending on your needs you may choose to use either of these. They are entirely equivalent.</p><p>When either the <b>Maximized</b> or <b>Minimized</b> properties are changed back to false, the window is restored to regular mode, which is the <code>FrameProxy</code>&#8216;s <b>RestoredLocation</b> and <b>RestoredSize</b>.</p><h3 id="JavaFrame">Use of the JavaFrame property</h3><p>Note that all this relies on the undocumented hidden figure property <b>JavaFrame</b>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release (HG2?):</p><div
class="wp_syntax"><div
class="code"><pre style="font-family: monospace;"><span style="color: #000000;">>> jFrame = </span><span style="color: #0000ff;">get</span>(<span style="color: #0000ff;">gcf</span>,<span style="color: #800080;">'JavaFrame'</span>)
<span style="color: #ff0000;">Warning: figure JavaFrame property will be obsoleted in a future release.</span>
<span style="color: #000000;">For more information see the JavaFrame resource on the MathWorks web site.
(Type "warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame" to suppress this warning.) 

jFrame =
com.mathworks.hg.peer.FigurePeer@1ffbad6</span>
</pre></div></div><p>To remove the above warning I have used (note the <i><b>handle</b></i> wrapper, as <a
target="_blank" href="http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comment-2756">suggested</a> by Donn Shull):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span></pre></div></div><p>If and when <b>JavaFrame</b> does become obsolete in some future Matlab version, be sure to look in this blog for workarounds.</p><p>You may also wish to inform MathWorks on the dedicated webpage that they have set up for specifically this reason (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/javaframe">http://www.mathworks.com/javaframe</a>), how you are using <b>JavaFrame</b> and why it is important for you. This may help them to decide whether to keep <b>JavaFrame</b> or possibly add the functionality using other means.</p><p>Do you have a smart use for the figure&#8217;s minimization or maximization feature? or another use for <b>JavaFrame</b>? If so, please share your ideas in a <a
target="_blank" href="http://UndocumentedMatlab.com/blog/minimize-maximize-figure-window#respond">comment</a> below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Blurred Matlab figure window</title><link>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/#comments</comments> <pubDate>Wed, 20 Apr 2011 18:58:12 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2259</guid> <description><![CDATA[Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Following my post two weeks ago about <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">disabling an entire Matlab figure window</a>, and my article last week about <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/">setting the transparency of a figure window</a>, I would like to combine these two functionalities into a blurred-window effect for a disabled window.</p><h3 id="basic">The basic idea</h3><p>The basic idea, as reader Mory <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#comment-40154">pointed out</a> in a comment, is to overlay a semi-transparent empty figure window, having just the right size and position, on top of the main (disabled) figure window:</p><p><center><div
class="wp-caption aligncenter" style="width: 640px"><img
alt="Main (unblurred) window" src="http://UndocumentedMatlab.com/images/blurFigure1a.png" title="Main (unblurred) window" width="190" /> + <img
alt="Semi-transparent window" src="http://UndocumentedMatlab.com/images/blurFigure1b.png" title="Semi-transparent window" width="190" /> = <img
alt="Blurred window effect" src="http://UndocumentedMatlab.com/images/blurFigure1c.png" title="Blurred window effect" width="190" /><p
class="wp-caption-text">Main (unblurred) window + semi-transparent window = blurred window effect</p></div></center></p><p>In addition to ensuring the correct figure size and position, there are several other things we should care for: We need to synchronize the figure/blurring color, menubar/toolbar, and title. We also need to handle docking, resizing and figure movement. Finally we need to connect the two figures so that whenever one is closed then so is the other.</p><h3 id="blurFigure">blurFigure</h3><p>My <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30666-blurfigure-blurs-and-prevents-interaction-on-a-figure-window"><i><b>blurFigure</b></i> utility</a> on the Matlab File Exchange attempts to handle all these setups for the user. The utility is quite simple to use:</p><p><i><b>blurFigure</b>(hFig)</i> blurs figure <i>hFig</i> and prevents interaction with it. The only interaction possible is with user-created controls on the blurring panel (see below).</p><p>hFigBlur = <i><b>blurFigure</b>(hFig)</i> returns the overlaid blurred figure pane. This is useful to present a progress bar or other GUI controls, for user interaction during the blur phase (see the demo below).</p><p><i><b>blurFigure</b>(hFig,STATE)</i> sets the blur status of figure <i>hFig</i> to <i>STATE</i>, where state is &#8216;on&#8217;,'off&#8217;,true or false (default=&#8217;on&#8217;/true). <i><b>blurFigure</b>(hFig,&#8217;on&#8217;)</i> or <i><b>blurFigure</b>(hFig,true)</i> is the same as: <i><b>blurFigure</b>(hFig)</i>; <i><b>blurFigure</b>(hFig,&#8217;off&#8217;)</i> or <i><b>blurFigure</b>(hFig,false)</i> is the same as: <i><b>close</b>(hFigBlur)</i>.</p><p><i><b>blurFigure</b>(&#8216;demo&#8217;)</i> displays a simple demo of the blurring. In fact, this runs the following simple code:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create the main (blurred) figure window</span>
hFigMain = <span style="color: #0000FF;">figure</span>;
&nbsp;
<span style="color: #228B22;">% Display some GUI controls in the main window</span>
<span style="color: #0000FF;">try</span> oldWarn = <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'off'</span>,<span style="color:#A020F0;">'MATLAB:uitree:MigratingFunction'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
hTree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'root'</span>,<span style="color:#A020F0;">'c:\'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">drawnow</span>;
<span style="color: #0000FF;">try</span> hTree.<span style="">getTree</span>.<span style="">expandRow</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span>oldWarn<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'click me!'</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">300</span>,<span style="color: #33f;">50</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">axes</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,<span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">230</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">300</span><span style="color: #080;">&#93;</span><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>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'ToolBar'</span>,<span style="color:#A020F0;">'figure'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% restore the toolbar that was removed by the uicontrol() call above</span>
&nbsp;
<span style="color: #228B22;">% Call blurFigure() to add a semi-transparent overlaid window</span>
hFigBlurTemp = blurFigure<span style="color: #080;">&#40;</span>hFigMain<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add some non-blurred controls on top of the blur</span>
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hFigBlurTemp, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'text'</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">130</span>,<span style="color: #33f;">85</span>,<span style="color: #33f;">390</span>,<span style="color: #33f;">80</span><span style="color: #080;">&#93;</span>, <span style="color: #F0F;">...</span>
          <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Processing - please wait...'</span>, <span style="color:#A020F0;">'FontSize'</span>,<span style="color: #33f;">12</span>, <span style="color:#A020F0;">'FontWeight'</span>,<span style="color:#A020F0;">'bold'</span>,<span style="color:#A020F0;">'Fore'</span>,<span style="color:#A020F0;">'red'</span>,<span style="color:#A020F0;">'Back'</span>,<span style="color:#A020F0;">'yellow'</span><span style="color: #080;">&#41;</span>;
jProgressBar = javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JProgressBar'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">180</span>,<span style="color: #33f;">115</span>,<span style="color: #33f;">310</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>, hFigBlurTemp<span style="color: #080;">&#41;</span>;
jProgressBar.<span style="">setValue</span><span style="color: #080;">&#40;</span><span style="color: #33f;">67</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hFigBlurTemp, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Cancel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">280</span>,<span style="color: #33f;">90</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'Callback'</span>,<span style="color:#A020F0;">'close(gcbf)'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 410px"><img
alt="Non-blurred controls displayed over a blurred figure window" src="http://UndocumentedMatlab.com/images/blurFigure.png" title="Non-blurred controls displayed over a blurred figure window" width="400" /><p
class="wp-caption-text">Non-blurred controls displayed over a blurred figure window</p></div></center></p><p>Do you have some other interesting uses for window transparency in Matlab? If so, please share your thought in a <a
href="http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/#respond">comment</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Transparent Matlab figure window</title><link>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#comments</comments> <pubDate>Wed, 13 Apr 2011 23:22:38 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Desktop]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2246</guid> <description><![CDATA[Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Every now and then, a user asks whether it is possible to make an entire Matlab window transparent (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/280394">example</a>). This could be used, for example, for window fade-in/fade-out effects. The short answer is that there is no supported way of doing this with pure documented Matlab, but it is trivially easy to achieve using just a bit of Java magic powder (surprise, surprise).</p><h3 id="transparency">Matlab figure window transparency</h3><p>Following an idea I got from Malcolm Lidierth&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28326-mutilities">MUtilities</a> submission on the Matlab File Exchange, the solution for setting Matlab figure window transparency is quite simple: Get the figure&#8217;s underlying Java window reference handle, as in <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">last week&#8217;s</a> article. Then use Java&#8217;s <a
target="_blank" rel="nofollow" href="http://www.pushing-pixels.org/2008/02/27/translucent-and-shaped-windows-in-core-java.html"><i>setWindowOpacity</i> method</a> to set the window&#8217;s transparency value. Actually, <i>setWindowOpacity</i> sets the opacity level, rather than transparency, but they are obviously complementary and I personally find &#8220;transparency&#8221; to be more easily understandable.</p><p>By default, windows are created with an opacity of 1.0 (= not transparent). They can be set to any floating-point value between 0.0-1.0, where an opacity of 0.0 means full transparency, and any value in between means partial transparency (i.e., translucency):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jWindow = jFigPeer.<span style="">fFigureClient</span>.<span style="">getWindow</span>;
com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,<span style="color: #33f;">0.7</span><span style="color: #080;">&#41;</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 510px"><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fx_files/30583/1/setFigTransparency.png"><img
alt="Semi-transparent (translucent) Matlab figure (click to enlarge)" src="http://www.mathworks.com/matlabcentral/fx_files/30583/1/setFigTransparency.png" title="Semi-transparent (translucent) Matlab figure (click to enlarge)" width="500" /></a><p
class="wp-caption-text">Semi-transparent (translucent) Matlab figure (click to enlarge)</p></div></center></p><p>Similarly, you can set the entire Matlab Desktop&#8217;s transparency/opacity value:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jDesktop = com.<span style="">mathworks</span>.<span style="">mde</span>.<span style="">desk</span>.<span style="">MLDesktop</span>.<span style="">getInstance</span>.<span style="">getMainFrame</span>;
com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jDesktop, <span style="color: #33f;">0.8</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Note that the <code>com.sun.awt.AWTUtilities</code> class also enables <a
target="_blank" rel="nofollow" href="http://today.java.net/pub/a/today/2008/03/18/translucent-and-shaped-swing-windows.html">other GUI effects</a> that would make a Matlab GUI developer&#8217;s mouth to start drooling: shaped windows, per-pixel transparency values, mirroring/reflection, window shadows, <a
target="_blank" rel="nofollow" href="http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/">gradients</a> etc. Perhaps I&#8217;ll explore their adaptation for Matlab figures someday.</p><h3 id="Fade">Fade-in / fade-out</h3><p>Window fade-in/fade-out effects can easily be achieved using transparency: Simply invoke the <i>setWindowOpacity</i> method several times, with progressively higher or lower values. This is easily done in a simple blocking loop. For example, to fade-out a window:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">for</span> stepIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">5</span>
   newAlpha = <span style="color: #33f;">1.0</span> - <span style="color: #33f;">0.2</span>*stepIdx;
   com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,newAlpha<span style="color: #080;">&#41;</span>;
   jWindow.<span style="">repaint</span>;
   <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.2</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% seconds</span>
<span style="color: #0000FF;">end</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
alt="Gradual window fade-out" src="http://UndocumentedMatlab.com/images/transparent_figure_animated.gif" title="Gradual window fade-out" width="300" /><p
class="wp-caption-text">Gradual window fade-out</p></div></center></p><p>A more general example dynamically computes the opacity step size/duration and also enables non-blocking fade effects using an asynchronous timer:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Compute the required opacity-setting steps</span>
fadeDuration = <span style="color: #33f;">1.5</span>;  <span style="color: #228B22;">% seconds</span>
oldAlpha = com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">getWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow<span style="color: #080;">&#41;</span>;
newAlpha = <span style="color: #33f;">0.0</span>;
deltaAlpha = newAlpha - oldAlpha;
maxStepAlpha = <span style="color: #33f;">0.03</span>;
steps = <span style="color: #0000FF;">fix</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>deltaAlpha<span style="color: #080;">&#41;</span> / maxStepAlpha<span style="color: #080;">&#41;</span> + <span style="color: #33f;">1</span>;
stepAlpha = deltaAlpha / steps;
stepDuration = fadeDuration / <span style="color: #080;">&#40;</span>steps-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% If blocking, do the fade effect immediately</span>
<span style="color: #0000FF;">if</span> blockingFlag <span style="color: #F0F;">||</span> steps==<span style="color: #33f;">1</span>
   <span style="color: #0000FF;">for</span> stepIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> steps
      newAlpha = oldAlpha + stepAlpha*stepIdx;
      com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,newAlpha<span style="color: #080;">&#41;</span>;
      jWindow.<span style="">repaint</span>;
      <span style="color: #0000FF;">if</span> stepIdx &lt; steps,  <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span>stepDuration<span style="color: #080;">&#41;</span>;  <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">else</span>
   <span style="color: #228B22;">% non-blocking: fade in/out asynchronously using a dedicated timer</span>
   start<span style="color: #080;">&#40;</span>timer<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'ExecutionMode'</span>,<span style="color:#A020F0;">'fixedRate'</span>, <span style="color:#A020F0;">'Period'</span>,<span style="color: #33f;">0.1</span>, <span style="color:#A020F0;">'TasksToExecute'</span>,steps, <span style="color: #F0F;">...</span>
               <span style="color:#A020F0;">'TimerFcn'</span>, <span style="color: #080;">&#123;</span>@timerFcn,jWindow,oldAlpha,stepAlpha<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Timer function for non-blocking fade-in/fade-out effect</span>
<span style="color: #0000FF;">function</span> timerFcn<span style="color: #080;">&#40;</span>hTimer,eventData,jFrame,currentAlpha,stepAlpha<span style="color: #080;">&#41;</span>  <span style="color: #228B22;">%#ok&lt;INUSL&gt; eventData</span>
  stepIdx = hTimer.<span style="">TasksExecuted</span>;
  newAlpha = currentAlpha + stepAlpha*stepIdx;
  com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jFrame,newAlpha<span style="color: #080;">&#41;</span>;
  jFrame.<span style="">repaint</span>;
  <span style="color: #0000FF;">if</span> stepIdx == hTimer.<span style="">TasksToExecute</span>
      stop<span style="color: #080;">&#40;</span>hTimer<span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>hTimer<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% timerFcn</span></pre></div></div><p>Of course, you can also fade-in/out to intermediate values such as 0.3 or 0.8. If you fade-out completely (i.e., to a value of 0.0), it might be a good idea to actually <i><b>close</b></i> the figure window once it gets the totally-transparent value of 0.0.</p><p>I&#8217;ve prepared a Matlab utility that contains all these options, including optional blocking/non-blocking fade effects, in my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30583-setfigtransparency-set-figure-transparency-fading"><i><b>setFigTransparency</b></i> utility</a>, which is available for download on the Matlab File Exchange. You may also wish to use Malcolm Lidierth&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28326-mutilities">MUtilities</a>, which also has similar functionalities (plus some other goodies).</p><h3 id="Limitations">Limitations</h3><p>Setting a figure window&#8217;s transparency requires using Java Run-time Engine (JRE) 1.6.0_10 (also called &#8220;Java 6 update 10&#8243;) or higher. This means that it&#8217;s supported on Matlab release 7.9 (R2009b) and higher by default, and on earlier releases using a JRE retrofit.</p><p>If you are using an earlier Matlab release, consider a retrofit of JRE 1.6.0_10 or any later version (e.g., the latest available version today is 1.6 update 24). The JRE can be downloaded from <a
target="_blank" rel="nofollow" href="http://java.com/en/download/manual.jsp">here</a>, and you can configure Matlab to use it according to the instructions <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-1812J/">here</a>. As noted, Matlab R2009b (7.9) and onward, at least on Microsoft Windows, pre-bundle a JRE version that does support transparency/opacity and so do not require a retrofit.</p><p>You can check your current Java version in Matlab as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">&gt;&gt; version -java
ans =
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode</pre></div></div><p>Unfortunately, Matlab plot axes cannot be made transparent. If you have any axes in your GUI, the axes area will simply appear as a shaded axes, whose intensity depends on the selected alpha (transparency) value; the contents beneath the window will not be merged in the axes area as it is in the non-axes areas.</p><p>Finally, note that <code>com.sun.awt.AWTUtilities</code> is itself an undocumented Java class. It is bundled with the standard Java release since 2008 (1.6.0_10), and yet is not part of the official release because its API has not yet settled. In fact, in the upcoming Java 7 release, which is expected in a few months, and which I expect to be available in Matlab sometime in 2012, the set of transparency/opacity methods have <a
target="_blank" rel="nofollow" href="http://www.pushing-pixels.org/2009/05/03/translucent-and-shaped-windows-in-jdk-7.html">migrated</a> to the fully-documented <code>java.awt.Window</code> class.</p><h3 id="blurring">Blurred figure window</h3><p>So here&#8217;s a riddle for you: using figure window transparency, can you guess how to make a Matlab figure appear blurred for <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">disabled figures</a> (see the screenshot there)? There are several possible ways to do this &#8211; can you find the simplest? The first one to <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#respond">post a comment</a> with a correct answer gets a smiley&#8230; My answer will appear in next week&#8217;s article.</p><h3 id="upgrade">Upgraded website</h3><p>Also, did you notice my new website design? It&#8217;s supposed to be much more readable (yes &#8211; also on <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2010/05/24/introducing-matlab-mobile-%E2%80%93-an-iphone-app-to-connect-remotely-to-your-matlab/#comments">Android</a>&#8230;). It now also runs on a multi-server cloud, which means more stability and faster response times. Do you like the new design? hate it? I would love to hear your feedback via <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#respond">comment</a> or <a
href="mailto:%20altmany%20@gmail.com?subject=Undocumented%20Matlab&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=Undocumented Matlab&amp;body=Hi Yair, '); return false;">email</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Enable/disable entire figure window</title><link>http://undocumentedmatlab.com/blog/disable-entire-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/disable-entire-figure-window/#comments</comments> <pubDate>Wed, 06 Apr 2011 18:00:20 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2089</guid> <description><![CDATA[Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Some time ago, a reader on the CSSM newsgroup <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/300200">asked</a> whether it is possible to disable an entire figure window while some processing is taking place. Last week, Mike posted an article about the built-in functions <b><i>uiwait</i></b> and <b><i>uiresume</i></b> on <a
rel="nofollow" target="_blank" href="http://blogs.mathworks.com/desktop/2011/03/28/using-uiwaituiresume-to-control-program-flow/">MathWork&#8217;s Matlab Desktop blog</a>, which more-or-less answers this need. Today I will expand the answer based on several undocumented/unsupported mechanisms.</p><h3 id="uiwait">Uiwait and uiresume</h3><p>We start with a short review of the supported mechanism: We can use the built-in <b><i>uiwait</i></b> function to suspend Matlab processing until either the specified handle (typically a figure handle) is deleted/closed, a user callback programmatically calls <b><i>uiresume</i></b>, or Ctrl-C is pressed. A short example, adapted from <b><i>uiwait</i></b>&#8216;s help section (the official help section has a bug, so if anyone reads this at TMW, please fix):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">h = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">20</span> <span style="color: #33f;">20</span> <span style="color: #33f;">200</span> <span style="color: #33f;">40</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'String'</span>, <span style="color:#A020F0;">'Continue'</span>, <span style="color:#A020F0;">'Callback'</span>, <span style="color:#A020F0;">'uiresume(gcbf)'</span><span style="color: #080;">&#41;</span>;
f = <span style="color: #0000FF;">gcf</span>;
<span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'This will print immediately'</span><span style="color: #080;">&#41;</span>;
uiwait<span style="color: #080;">&#40;</span>f<span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'This will print after you click Continue or close the window'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Close the figure (use try-catch in case f is already closed)</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">close</span><span style="color: #080;">&#40;</span>f<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span></pre></div></div><p>Unfortunately, the side effect is that <b><i>uiwait</i></b> blocks the regular (non-callback&#8217;ed) processing until the lock is released. This is great for simple cases where we require a user to respond to a popup window (e.g., message-box or input dialog) before being allowed to proceed. In more complex situations we may wish to suspend interaction on certain figure windows while continuing to process Matlab functionality &#8211; this is impossible to do using <b><i>uiwait</i></b>.</p><p>Matlab does not have any documented way to disable an entire figure window. You can set the figure&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/figure_props.html#WindowStyle"><b>WindowStyle</b> property</a> to &#8216;modal&#8217; but this is not the same: (1) it removes the toolbar and menu-bar (2) it still enables interaction with all the figure&#8217;s GUI controls and (3) it prevents access to any other Matlab window or desktop until the modal figure is closed. This is certainly NOT what we need.</p><p>Of course, we could always loop over all the relevant GUI handles and set their <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#Enable"><b>Enable</b> property</a> to &#8216;inactive&#8217; or &#8216;off&#8217;. But this is tedious, lengthy, and in complex GUIs that have multiple layers of nested panels, it also requires careful recursive programming. We also need to take care to disable hidden handles, toolbars, menu-bars, context-menus, Java components &#8211; all these have different ways of being accessed and disabled. And once we <b><i>uiresume</i></b> from the lock, we need to remember each handle&#8217;s pre-<b><i>uiwait</i></b> state, so that if it was disabled before the call to <b><i>uiwait</i></b>, it will remain so after <b><i>uiresume</i></b>. In short, this is not a trivial exercise at all.</p><h3 id="uisuspend">Uisuspend and uirestore</h3><p>To complicate things, the fully-documented and supported <b><i>uiwait</i></b> and <b><i>uiresume</i></b> functions have the <a
target="_blank" href="http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> unsupported built-in counterparts <b><i>uisuspend</i></b> and <b><i>uirestore</i></b>, which are very similar in functionality and name. It is important not to confuse between these two function sets, and most importantly, not to confuse between <b><i>uiresume</i></b> and <b><i>uirestore</i></b> after using their counterparts earlier in the code – odd things might happen if you do&#8230;</p><p>Hopefully, in a nearby Matlab release these inconsistencies between the two function sets will disappear and they will be merged, because the current situation is prone to errors and confusion. For backward compatibility considerations, I hope that <b><i>uisuspend</i></b> and <b><i>uirestore</i></b> would not be discontinued but rather be modified to simply call <b><i>uiwait</i></b> and <b><i>uiresume</i></b>.</p><p>Note that in Matlab releases up to R2010b, <b><i>uirestore</i></b> had a <a
rel="nofollow" target="_blank" href="http://www.mathworks.com/support/bugreports/646025 ">minor bug</a> in that it overwrites the figure&#8217;s <b>WindowScrollWheelFcn</b> callback with the <b>WindowKeyPressFcn</b> value. This bug was finally fixed in R2011a.</p><h3 id="Method">How to enable/disable a figure window</h3><p>So going back to the main question, we want to find a way to disable an entire figure window, in one simple stroke, and without blocking the Matlab processing.</p><p>As usual, we turn to Java and the solution is trivially simple:</p><p>First, get the figure window&#8217;s underlying Java reference. Note that we need the top-level container reference, rather than the proxy peer handle returned by the <b>JavaFrame</b> hidden property:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>
jFigPeer =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigurePeer</span>@1ffbad6
&nbsp;
&gt;&gt; jWindow = jFigPeer.<span style="">fFigureClient</span>.<span style="">getWindow</span>
<span style="color: #0000FF;">ans</span> =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigureFrameProxy</span>$FigureFrame<span style="color: #080;">&#91;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span></pre></div></div><p>Now remember that all Java GUI components (on which Matlab GUI is based) contain an <a
target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/java/awt/Component.html#setEnabled%28boolean%29"><b>Enabled</b> property</a>. So, simply set this property on the jWindow reference to true or false:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jWindow.<span style="">setEnabled</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or true</span>
&nbsp;
<span style="color: #228B22;">% an equivalent alternative</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>jWindow<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Enabled'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% or true</span></pre></div></div><p>By the way, if you only need to disable the figure&#8217;s content area (i.e., not the toolbar and menu bar), simply use a different reference handle:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer.<span style="">getFigurePanelContainer</span>.<span style="">setEnabled</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or true</span></pre></div></div><p>Notes:</p><ul><li>While the window looks the same when it is disabled, in reality none of its GUI elements can be clicked or activated (try it!). If you also want the figure to appear blurred you could try using something like a <a
target="_blank" rel="nofollow" href="http://java.net/projects/jxlayer/">JXLayer</a> semi-translucent glass pane.</li><li>The Java components&#8217; property is called <b>Enabled</b>, not <b>Enable</b> as in pure-Matlab Handle-Graphics controls. Also, the Java property expects true/false (or 0/1), rather than Matlab&#8217;s &#8216;on&#8217;/'off&#8217; (there are some fine details here that are release-specific so I will skip them)</li><li>For docked windows the top-level window is the figure&#8217;s group container window or the desktop window, which we do not want to disable. Detecting this is easy (check whether the figure&#8217;s <b>WindowStyle</b> is &#8216;docked&#8217;), and in such cases simply disable/enable the figure&#8217;s content area as shown above.</li></ul><h3 id="JavaFrame">Use of the JavaFrame property</h3><p>Note that all this relies on the undocumented hidden figure property <b>JavaFrame</b>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release (HG2?):</p><div
class="wp_syntax"><div
class="code"><pre style="font-family: monospace;"><span style="color: #000000;">>> jFigPeer = </span><span style="color: #0000ff;">get</span>(<span style="color: #0000ff;">gcf</span>,<span style="color: #800080;">'JavaFrame'</span>)
<span style="color: #ff0000;">Warning: figure JavaFrame property will be obsoleted in a future release.</span>
<span style="color: #000000;">For more information see the JavaFrame resource on the MathWorks web site.
(Type "warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame"
to suppress this warning.) 

jFigPeer =
com.mathworks.hg.peer.FigurePeer@1ffbad6</span>
</div>
</div>
</pre><p>To remove the above warning I have used (note the <i><b>handle</b></i> wrapper, as <a
target="_blank" href="http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comment-2756">suggested</a> by Donn Shull):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span></pre></div></div><p>If and when <b>JavaFrame</b> does become obsolete in some future Matlab version, be sure to look in this blog for workarounds.</p><p>You may also wish to inform MathWorks on the dedicated webpage that they have set up for specifically this reason (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/javaframe">http://www.mathworks.com/javaframe</a>), how you are using <b>JavaFrame</b> and why it is important for you. This may help them to decide whether to keep <b>JavaFrame</b> or possibly add the functionality using other means.</p><h3 id="enableDisableFig">The enableDisableFig utility</h3><p>In 2007, I created the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15895-enabledisable-figure"><i><b>enableDisableFig</b></i> utility</a> that wraps the above code in an easy-to-use Matlab utility that I have uploaded to the File Exchange.</p><p><i><b>enableDisableFig</b></i> returns the current state of the specified figure handle (or <i><b>gcf</b></i> if no handle is specified), and optionally sets the figure&#8217;s enabled/disabled state to a new value (&#8216;on&#8217;,'off&#8217;, true or false):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; oldState = enableDisableFig<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>
oldState =
on
&nbsp;
&gt;&gt; enableDisableFig<span style="color: #080;">&#40;</span>oldState<span style="color: #080;">&#41;</span>;
&gt;&gt; enableDisableFig<span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative</span></pre></div></div><p><i><b>enableDisableFig</b></i> also provides some sanity checks and error handling that should always appear in any real-world application. In this blog I generally tend to provide only bare-bones code snippets (as above). But in any respected application we must check the validity of input arguments and return values, catch run-time errors, compensate for incompatibilities with older Matlab release and so on. Take a look at <i><b>enableDisableFig</b></i>&#8216;s source code to see how I have done this.</p><h3 id="visual">Visual aid</h3><p>When any GUI control is disabled, the accepted convention is to shade it in a gray color as a visual aid to the user that the control is currently disabled. This is automatically done by Matlab when any control&#8217;s <b>Enable</b> property is set to &#8216;off&#8217;. In our case, it would be very helpful to display a similar blurring effect for the disabled figure window.</p><p>Would you be very surprised if I told you that this is impossible to do with regular Matlab, but trivially easy to achieve using a tiny bit of Java magic powder? I&#8217;ll expand on this in my next post, but here&#8217;s something to keep you waiting:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="A blurred disabled figure" src="http://UndocumentedMatlab.com/images/blurFigure.png" title="A blurred disabled figure" width="450" /><p
class="wp-caption-text">A blurred disabled figure</p></div></center></p><h3 id="upgrade">Server upgrade</h3><p>This weekend (9-10 April, 2011) I plan to upgrade the website. This will entail moving to a different webserver, database, upgraded blogging application, new design etc. This site may be down or &#8220;goofy&#8221; for quite a few hours. Hopefully all will be back to normal by Monday and I hope you will like the new design.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/disable-entire-figure-window/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</title><link>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/</link> <comments>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/#comments</comments> <pubDate>Wed, 06 Jan 2010 21:06:33 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[PixelBounds]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=892</guid> <description><![CDATA[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.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/' rel='bookmark' title='FindJObj GUI &#8211; display container hierarchy'>FindJObj GUI &#8211; display container hierarchy</a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-type-selection-components/' rel='bookmark' title='Plot-type selection components'>Plot-type selection components</a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>In a previous post, I explained that all Matlab GUI (except the axes plotting engine) is based on Java components, and showed how we can use this information to <a
target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">display HTML contents in Matlab <b><i>uicontrol</i></b>s</a>. In <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/findjobj/">other posts</a>, I have shown how a utility called <b><i>findjobj</i></b> can be used to access the underlying Java components to enable customizations that are unavailable in standard Matlab: <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/">setting the line location in an edit-box</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/button-customization/">customizing button appearance</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/">setting uicontrol callbacks</a>, or <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/">setting list-box mouse actions</a>. I have also shown how <b><i>findjobj</i></b> can be used to display the component hierarchy of complex Matlab containers such as the <a
target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-customizations/">figure window</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/guide-customization/">GUIDE</a> or the <a
target="_blank" href="http://undocumentedmatlab.com/blog/accessing-the-matlab-editor/">Editor</a>.</p><p>The time is therefore well overdue for a formal introduction of <b><i>findjobj</i></b>, explaining its uses and internal mechanism. Of course, readers are welcome to continue using <b><i>findjobj</i></b> as a black-box utility, but I think important insight can be gained from understanding its inner details. <b><i>Findjobj</i></b>&#8216;s code is available for free download on the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">MathWorks File Exchange</a>. It is one of my favorite submissions and is apparently well-liked by users, being highly reviewed and highly downloaded.</p><p><b><i>Findjobj</i></b> has two main purposes:</p><ol><li>Find the underlying Java object reference of a given Matlab handle &#8211; Historically this was the original purpose, hence the utility&#8217;s name. <b><i>Findjobj</i></b> was meant to extend Matlab&#8217;s standard <b><i>findobj</i></b> function, which does not expose Java components.</li><li>Display a container&#8217;s internal components hierarchy in a graphical user interface, to facilitate visualization of complex containers. This was later extended to also display and allow modification of the sub-components&#8217; properties and callbacks.</li></ol><p>Today I will focus on the first (programmatic) aspect;  next week I will describe the second (GUI) aspect.</p><p><b><i>Findjobj</i></b>&#8216;s heart is finding a control&#8217;s underlying Java handle. Unfortunately, this is not exposed by Matlab except in very rare cases. As hard as I tried, I could not find a way to directly access the underlying Java-peer handle. I therefore resorted to getting the control&#8217;s enclosing Java frame (window) reference, and then working down its sub-components hierarchy until finding the Java object(s) which satisfy the position and/or class criteria. To get the enclosing Java frame (aka <i>TopLevelAncestor</i>), I use the Matlab figure&#8217;s undocumented <b>JavaFrame</b> property. Using this property issues a standard warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release. Since it worked so far, I have turned off this warning in <b><i>findjobj</i></b>&#8216;s code, but note that this code may well fail in some future Matlab version. If and when <b>JavaFrame</b> does become obsolete, be sure to look in this blog for workarounds…</p><p>Traversing the frame&#8217;s hierarchy presents several challenges: Main-menu items are accessed using different functions than other Swing components or sub-containers, and are not automatically accessible until first displayed. I have overcome this latter challenge by simulating a menu-open action in case menus should be searched (this is off by default since it takes several seconds and also changes the GUI focus). For &#8220;regular&#8221; sub-containers, sometimes we need to loop over <i>getComponent(&#8230;)</i> and in some other cases over <i>getChildAt(&#8230;)</i>.</p><p>Another challenge was presented by the fact that Java positions start at (0,0) in the <u>top</u> left corner increasing rightward and <u>downward</u>, rather than starting at (1,1) in the bottom left and increasing upward as in Matlab. Moreover, Java positions are always pixel-based and relative to their parent container, which is different from Matlab (if the Matlab units is &#8216;pixels&#8217; then the value is absolute; if &#8216;normalized&#8217; then it returns a non-pixel value). To further complicate matters, some Matlab controls have a different size than their Java counterparts: some controls have a 5-pixel margins while others not, some controls are shifted by a pixel or two from their container&#8217;s border (for a total offset of up to 7 pixels), while some controls (such as popup-menus) have an entirely different reported size. In theory, we could use the Matlab component&#8217;s undocumented <b>PixelBounds</b> property (much faster than <b><i>getpixelposition</i></b>), but unfortunately <b>PixelBounds</b> turns out to be unreliable and returns erroneous values in many cases. Finally, different Java containers/components have different ways of returning their position: for some it is a <i>getLocation()</i> method, for others it is <i>getX()/getY()</i> and for others it is the <b>X</b> and <b>Y</b> properties (that sometimes have no corresponding <i>getX()/getY()</i> accessor methods!).</p><p>Having finally overcome all these challenges (and quite a few smaller ones, documented within the source code), I have wrapped the algorithm in a function interface that tries to emulate <b><i>findobj</i></b>&#8216;s. Using <b><i>findjobj</i></b> can now be as easy as:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Modify the mouse cursor when over the button</span>
hButton = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'click me!'</span><span style="color: #080;">&#41;</span>;
jButton = findjobj<span style="color: #080;">&#40;</span>hButton<span style="color: #080;">&#41;</span>;
jButton.<span style="">setCursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span>.<span style="">HAND_CURSOR</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 260px"><img
alt="Modified uicontrol cursor - a Java property" src="http://UndocumentedMatlab.com/images/button_cursor_hand.png" title="Modified uicontrol cursor - a Java property" width="105" height="66" /><p
class="wp-caption-text">Modified uicontrol cursor - a Java property</p></div></center></p><p>&#8230;or as complex as:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Find all non-button controls with the specified label</span>
jControls = findjobj<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'property'</span>,<span style="color: #080;">&#123;</span><span style="color:#A020F0;">'text'</span>,<span style="color:#A020F0;">'click me!'</span><span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'not'</span>,<span style="color:#A020F0;">'class'</span>,<span style="color:#A020F0;">'button'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Space here is limited and <b><i>findjobj</i></b> is over 2500 lines long, so I have obviously not covered everything. I encourage you to <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">download the utility</a> and explore the code, and I gladly welcome your feedback.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/' rel='bookmark' title='FindJObj GUI &#8211; display container hierarchy'>FindJObj GUI &#8211; display container hierarchy</a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-type-selection-components/' rel='bookmark' title='Plot-type selection components'>Plot-type selection components</a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>Detecting window focus events</title><link>http://undocumentedmatlab.com/blog/detecting-window-focus-events/</link> <comments>http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comments</comments> <pubDate>Wed, 09 Sep 2009 20:49:51 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[UIInspect]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=584</guid> <description><![CDATA[Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A CSSM reader <a
target="_blank rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/260078#678945">recently asked</a> whether it is possible to detect window focus events (specifically, the focus-gain event) asynchronously, so that such events can trigger a callback without necessitating a polling thread to constantly monitor the windows state.</p><p>The user correctly mentioned the fact that although mouse-clicks within the window frame can be detected using the documented figure callback <b><i>WindowButtonDownFcn</i></b>, there are other methods by which a window can gain focus: keyboard (&lt;Alt&gt;-&lt;Tab&gt; on Windows, for example), clicking the window frame edge etc. These methods are all undetected by <b><i>WindowButtonDownFcn</i></b>.</p><p>This problem is, to the best of my knowledge, insoluble using standard documented Matlab. However, there is indeed a simple solution using undocumented/unsupported Matlab features. The solution relies on the fact that all Matlab windows are basically Java Swing objects, and these objects have dozens of standard callback hooks that can be utilized (Matlab only exposes a few callbacks). The list of standard Swing callbacks was detailed in my earlier article about <a
target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/">uicontrol callbacks</a>, which is also relevant for Java window frames.</p><p>In this specific case, we are interested in <b><i>FocusGainedCallback</i></b>. This callback is invoked for the figure Frame&#8217;s AxisComponent (a part of the Frame that will be explained in another article). For each of our monitored figure windows, we set this callback to a predefined Matlab function. We may also wish to set its companion <b><i>FocusLostCallback</i></b>.</p><p>Here&#8217;s the resulting code snippet (hFig is our Matlab figure handle):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Prepare the figure</span>
hFig = <span style="color: #0000FF;">figure</span>;  <span style="color: #228B22;">% etc. - prepare the figure</span>
&nbsp;
<span style="color: #228B22;">% Get the underlying Java reference</span>
<span style="color: #0000FF;">warning</span> off MATLAB<span style="color: #F0F;">:</span>HandleGraphics<span style="color: #F0F;">:</span>ObsoletedProperty<span style="color: #F0F;">:</span>JavaFrame
jFig = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jAxis = jFig.<span style="">getAxisComponent</span>;
&nbsp;
<span style="color: #228B22;">% Set the focus event callback</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jAxis,<span style="color:#A020F0;">'FocusGainedCallback'</span>,<span style="color: #080;">&#123;</span>@myMatlabFunc,hFig<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% perhaps also set the FocusLostCallback here</span></pre></div></div><p>Whenever any of the monitored figures now gets focus, by whichever means, the user-defined Matlab function myMatlabFunc() will be invoked. This function should be defined as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myMatlabFunc<span style="color: #080;">&#40;</span>jAxis, jEventData, hFig<span style="color: #080;">&#41;</span>
   <span style="color: #228B22;">% do whatever you wish with the event/hFig information</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>Extra input parameters can be added during callback setup and definition, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jAxis,<span style="color:#A020F0;">'FocusLostCallback'</span>,<span style="color: #080;">&#123;</span>@myMatlabFunc,hFig,data1,data2<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
<span style="color: #F0F;">...</span>
<span style="color: #0000FF;">function</span> myMatlabFunc<span style="color: #080;">&#40;</span>jAxis, jEventData, hFig, data1, data2<span style="color: #080;">&#41;</span>
   <span style="color: #228B22;">% do whatever you wish with the event/hFig/data information</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>A very similar technique can detect other windowing events (maximization/minimization/movement etc.). Depending on the case, you may need to use <i>jFig.fFigureClient.getWindow</i> instead of <i>jFig.getAxisComponent</i>. The list of available callbacks for each of these objects can be seen using a simple <i><b>set</b>(jFig.getAxisComponent)</i> command, or via my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect</a> or <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj</a> utilities on the Matlab File Exchange.</p><p>Note that all this relies on the undocumented hidden figure property <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/javaframe/"><b><i>JavaFrame</i></b></a>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release. Since it worked so far, I have turned off this warning in the code above, but note that this code may well fail in some future Matlab version. If and when JavaFrame does become obsolete, be sure to look in this blog for workarounds&#8230;</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/detecting-window-focus-events/feed/</wfw:commentRss> <slash:comments>24</slash:comments> </item> <item><title>Setting status-bar components</title><link>http://undocumentedmatlab.com/blog/setting-status-bar-components/</link> <comments>http://undocumentedmatlab.com/blog/setting-status-bar-components/#comments</comments> <pubDate>Thu, 30 Jul 2009 10:09:10 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=478</guid> <description><![CDATA[Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels<pre> </pre>Related posts:<ol><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/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><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><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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>I last week&#8217;s post, <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-status-bar-text/">Setting status-bar text</a>, I showed how to set the status-bar text in Matlab figures and the main desktop. But Matlab status-bars are Java containers in which we can add GUI controls, not just simple text labels. In this post I will show how to do this for Matlab 7 figures.</p><p>Let&#8217;s return to the two alternatives I&#8217;ve presented in my previous post for setting a Matlab 7 figure status-bar text:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternative #1 (hFig = requested figure's handle)</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jFigPanel = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'FigurePanelContainer'</span><span style="color: #080;">&#41;</span>;
jRootPane = jFigPanel.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>.<span style="">getRootPane</span>;
jRootPane = jRootPane.<span style="">getTopLevelAncestor</span>;
statusbarObj = jRootPane.<span style="">getStatusBar</span>;
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;
jRootPane.<span style="">setStatusBarVisible</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative #2</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jRootPane = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span>;
statusbarObj = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJStatusBar</span>;
jRootPane.<span style="">setStatusBar</span><span style="color: #080;">&#40;</span>statusbarObj<span style="color: #080;">&#41;</span>;
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;</pre></div></div><p>The first alternative uses the default status-bar (a com.mathworks.mwswing.MJStatusBar object) which Matlab automatically creates with each figure. This object is created as invisible, so we need to set its text (via its <i>setText</i> method), and then make it visible (via its ancestor&#8217;s root-pane&#8217;s <i>setStatusBarVisible</i> method &#8211; setting the object itself to visible is not enough). The alternative is to replace the default status-bar object with a user-specified container (in this case, we use a new instance of com.mathworks.mwswing.MJStatusBar).</p><p>Last week I forgot to mention that only the second alternative works in the general case &#8211; it appears that the first alternative often fails because figures are not created with the default statusbar on many platforms/Matlab release (I&#8217;m not sure exactly which). My <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14773">StatusBar utility on the MathWorks File Exchange</a>, which I mentioned in last week&#8217;s post, takes care of these nuances, and automatically creates the status bar object if it is missing.</p><p>In any case, using these two code snippets as a baseline, we can customize any Java container that we wish. We are not limited to text labels. The default ststusbar container, MJStatusBar, only includes a single JLabel-derived component that stores the text message. We can add other components to this container. For example, let&#8217;s add a simple progress-bar:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jRootPane = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span>;
statusbarObj = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJStatusBar</span>;
&nbsp;
<span style="color: #228B22;">% Add a progress-bar to left side of standard MJStatusBar container</span>
jProgressBar = javax.<span style="">swing</span>.<span style="">JProgressBar</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jProgressBar, <span style="color:#A020F0;">'Minimum'</span>,<span style="color: #33f;">0</span>, <span style="color:#A020F0;">'Maximum'</span>,<span style="color: #33f;">500</span>, <span style="color:#A020F0;">'Value'</span>,<span style="color: #33f;">234</span><span style="color: #080;">&#41;</span>;
statusbarObj.<span style="">add</span><span style="color: #080;">&#40;</span>jProgressBar,<span style="color:#A020F0;">'West'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% 'West' =&gt; left of text; 'East' =&gt; right</span>
<span style="color: #228B22;">% Beware: 'East' also works but doesn't resize automatically</span>
&nbsp;
<span style="color: #228B22;">% Set this container as the figure's status-bar</span>
jRootPane.<span style="">setStatusBar</span><span style="color: #080;">&#40;</span>statusbarObj<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Note: setting setStatusBarVisible(1) is not enough to display the status-bar</span>
<span style="color: #228B22;">% - we also need to call setText(), even if only with an empty string ''</span>
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'testing 123...'</span><span style="color: #080;">&#41;</span>;
jRootPane.<span style="">setStatusBarVisible</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><br
/><div
class="wp-caption aligncenter" style="width: 438px"><img
alt="Status bar with a simple progress-bar" src="http://undocumentedmatlab.com/images/statusbar6a.png" title="Status bar with a simple progress-bar" width="428" height="271" /><p
class="wp-caption-text">Status bar with a simple progress-bar</p></div><br
/></center></p><p>We can of course use the progress-bar and status-bar handles to modify their appearance within our code, for example within some loop. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">numIds = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>allIds<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jProgressBar, <span style="color:#A020F0;">'StringPainted'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color:#A020F0;">'Maximum'</span>,numIds, <span style="color:#A020F0;">'Value'</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">for</span> id = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> numIds
&nbsp;
   <span style="color: #228B22;">% Update status bar</span>
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jProgressBar, <span style="color:#A020F0;">'StringPainted'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color:#A020F0;">'Value'</span>,id<span style="color: #080;">&#41;</span>;
   msg = <span style="color:#A020F0;">'Processing %d of %d (%.1f%%)...'</span>;
   statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span>msg,id,numIds,<span style="color: #33f;">100</span>*id/numIds<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% do something useful...</span>
&nbsp;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% for all Ids</span>
&nbsp;
<span style="color: #228B22;">% Some final status-bar updates...</span>
<span style="color: #228B22;">% Hide the progress-bar</span>
jProgressBar.<span style="">setVisible</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Hide the corner grip</span>
cornerGrip = statusbarObj.<span style="">getParent</span>.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
cornerGrip.<span style="">setVisible</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or: set(cornerGrip,'Visible','off')</span>
&nbsp;
<span style="color: #228B22;">% Set a red foreground &amp; yellow background to status bar text</span>
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'All done - congratulations!!!'</span><span style="color: #080;">&#41;</span>;
statusbarTxt = statusbarObj.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
statusbarTxt.<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>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>statusbarTxt,<span style="color:#A020F0;">'Background'</span>,<span style="color:#A020F0;">'yellow'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>statusbarTxt,<span style="color:#A020F0;">'Background'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative…</span></pre></div></div><p><center><br
/><div
class="wp-caption aligncenter" style="width: 430px"><img
alt="Modifying status bar properties in run-timer" src="http://undocumentedmatlab.com/images/statusbar_animated.gif" title="Modifying status bar properties in run-time" width="420" height="266" /><p
class="wp-caption-text">Modifying status bar properties in run-time</p></div><br
/></center></p><p>The progress-bar component was just a simple example of how to present non-intrusive controls/information in the figure status bar. Other controls (buttons, checkboxes etc.) can similarly be added.</p><p>Note that the status-bar&#8217;s corner-grip (at its far right) is not a sub-component of the statusbarObj object like the label, but rather of its parent JPanel container. This is easily be seen using my <a
target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/14317" rel="nofollow">FindJObj utility on the MathWorks File Exchange</a>:</p><p><center><br
/><div
class="wp-caption aligncenter" style="width: 430px"><img
alt="Status bar with a simple progress-bar" src="http://undocumentedmatlab.com/images/statusbar6d2.png" title="Status bar components hierarchy" width="420" height="509" /><p
class="wp-caption-text">Status bar with a simple progress-bar</p></div><br
/></center></p><p>One final note: The status bar is 20 pixels high across the entire bottom of the figure. It hides everything between pixel heights 0-20, even parts of uicontrols, regardless of who was created first or the relative ComponentZOrder in the frame&#8217;s ContentPane:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Add a &quot;Next phase&quot; button to the right of the text</span>
jb = javax.<span style="">swing</span>.<span style="">JButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Next phase &gt;'</span><span style="color: #080;">&#41;</span>;
jbh = handle<span style="color: #080;">&#40;</span>jb,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jbh, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, @nextPhaseFunction<span style="color: #080;">&#41;</span>;
statusbarObj.<span style="">add</span><span style="color: #080;">&#40;</span>jb,<span style="color:#A020F0;">'East'</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">%note: we might need jRootPane.setStatusBarVisible(0)</span>
<span style="color: #228B22;">% followed by jRootPane.setStatusBarVisible(1) to repaint</span>
&nbsp;
<span style="color: #228B22;">% Add a simple Matlab uicontrol, obscured by the status-bar</span>
hb = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'click me!'</span>, <span style="color:#A020F0;">'position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">15</span>,<span style="color: #33f;">70</span>,<span style="color: #33f;">30</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><br
/><div
class="wp-caption aligncenter" style="width: 438px"><img
alt="Adding controls inside and outside the status-bar" src="http://undocumentedmatlab.com/images/statusbar6e.png" title="Adding controls inside and outside the status-bar" width="428" height="244" /><p
class="wp-caption-text">Adding controls inside and outside the status-bar</p></div><br
/></center></p><p>If you have made interesting use of Matlab&#8217;s status-bar, please share them in the comments section below.</p><p><pre> </pre>Related posts:<ol><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/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><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><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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-status-bar-components/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Setting status-bar text</title><link>http://undocumentedmatlab.com/blog/setting-status-bar-text/</link> <comments>http://undocumentedmatlab.com/blog/setting-status-bar-text/#comments</comments> <pubDate>Thu, 23 Jul 2009 22:01:40 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Desktop]]></category> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[uitools]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=465</guid> <description><![CDATA[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.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><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/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><li><a
href='http://undocumentedmatlab.com/blog/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><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Most GUI windows nowadays, ranging from web browsers to editors and data-entry windows, have a small status-bar at their bottom. Statusbars are a great way to convey non-critical information to the user, in a non-intrusive manner (without popup windows).</p><p>Matlab windows are no exception: they too have status bars which are sometimes used by internal Matlab functions. Unfortunately, there is no documented way to modify Matlab statusbars. In this post I will demonstrate the undocumented way of setting status-bar text, which is probably the most useful use-case. In next week&#8217;s post, I will expand this to include more complex customizations, such as dynamic progress-bars or a corner grip.</p><p>Note: Users interested in non-intrusive status-bar messages, may also be interested in another non-intrusive messaging mechanism which I have described some months ago: <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/">Setting system tray popup messages</a>.</p><h3>Desktop window status-bar</h3><p>We start with the simplest case of setting the desktop&#8217;s statusbar text. We have no further to go than the bottom of Matlab&#8217;s own <b><i>uiopen</i></b> (see %matlabroot%/toolbox/matlab/uitools/uiopen.m):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">dt = javaMethod<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'getInstance'</span>, <span style="color:#A020F0;">'com.mathworks.mde.desk.MLDesktop'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">if</span> dt.<span style="">hasMainFrame</span>
    dt.<span style="">setStatusText</span><span style="color: #080;">&#40;</span>message<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">else</span>
    <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>message<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Basically, we try to get the Java reference to the Matlab desktop, see if it has an open window frame and if so then we use its <i>setStatusText()</i> method to display a text message; if not then we display the message in the Command Window (which is probably a non-window console).</p><p>Unfortunately, if we place this code in our m-files as-is, our status message will be overridden by Matlab&#8217;s &#8220;busy&#8221; message. A solution for this is to use a one-time (discardable) timer. Another complication is meant for supporting Matlab 6, in which we get the desktop reference differently, and which did not yet have the timer function. The final code now looks like this:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% Set the status bar text of the Matlab desktop</span>
<span style="color: #0000FF;">function</span> setDesktopStatus<span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>
  <span style="color: #228B22;">% First, get the desktop reference</span>
  <span style="color: #0000FF;">try</span>
    desktop = com.<span style="">mathworks</span>.<span style="">mde</span>.<span style="">desk</span>.<span style="">MLDesktop</span>.<span style="">getInstance</span>;     <span style="color: #228B22;">% Matlab 7+</span>
  <span style="color: #0000FF;">catch</span>
    desktop = com.<span style="">mathworks</span>.<span style="">ide</span>.<span style="">desktop</span>.<span style="">MLDesktop</span>.<span style="">getMLDesktop</span>; <span style="color: #228B22;">% Matlab 6</span>
  <span style="color: #0000FF;">end</span>
&nbsp;
  <span style="color: #0000FF;">if</span> desktop.<span style="">hasMainFrame</span>
    <span style="color: #228B22;">% Schedule a timer to update the status text</span>
    <span style="color: #228B22;">% Note: can't update immediately (will be overridden by Matlab's 'busy' message)</span>
    <span style="color: #0000FF;">try</span>
      timerFcn = <span style="color: #080;">&#123;</span>@setText,desktop,statusText<span style="color: #080;">&#125;</span>;
      t = timer<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'TimerFcn'</span>,timerFcn, <span style="color:#A020F0;">'StartDelay'</span>,<span style="color: #33f;">0.05</span>, <span style="color:#A020F0;">'ExecutionMode'</span>,<span style="color:#A020F0;">'singleShot'</span><span style="color: #080;">&#41;</span>;
      start<span style="color: #080;">&#40;</span>t<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">catch</span>
      <span style="color: #228B22;">% Probably an old Matlab version that still doesn't have timer</span>
      desktop.<span style="">setStatusText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">else</span>
    <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">%% Utility function used as setDesktopStatus's internal timer's callback</span>
<span style="color: #0000FF;">function</span> setText<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
  <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">nargin</span> == <span style="color: #33f;">4</span>  <span style="color: #228B22;">% just in case...</span>
    targetObj  = <span style="color: #0000FF;">varargin</span><span style="color: #080;">&#123;</span><span style="color: #33f;">3</span><span style="color: #080;">&#125;</span>;
    statusText = <span style="color: #0000FF;">varargin</span><span style="color: #080;">&#123;</span><span style="color: #33f;">4</span><span style="color: #080;">&#125;</span>;
    targetObj.<span style="">setStatusText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">else</span>
    <span style="color: #228B22;">% should never happen...</span>
  <span style="color: #0000FF;">end</span></pre></div></div><h3>Figure window status-bar</h3><p>Setting the status-bar text on figure windows is slightly more difficult: <b><i>getstatus</i></b> and <b><i>setstatus</i></b> appear to be early attempts by Matlab to enable users an access to a figure&#8217;s statusbar. In this early attempt, Matlab assumes that the user prepares a text label having a tag of &#8216;status&#8217;. <b><i>getstatus</i></b> then returns this label&#8217;s string, while <b><i>setstatus</i></b> modifies it:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Parent'</span>,<span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'Style'</span>,<span style="color:#A020F0;">'text'</span>,<span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'Status'</span><span style="color: #080;">&#41;</span>;
setstatus<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'Goodbye'</span><span style="color: #080;">&#41;</span>;
string = getstatus<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Unfortunately, nothing prevents the user from placing the label anywhere in the figure, and also from having multiple such labels at once, adding to the confusion. The result is inconsistent with normal windowing practices, and this is probably the reason that MathWorks have grandfathered these functions in Matlab 7.4 (R2007a). It would be much more logical for Matlab to have the statusbar accessible via a figure property, and perhaps this will happen in some future version.</p><p>A better, consistent and more flexible access to the figure statusbar can be achieved by using some undocumented Java functions. In a nutshell, we get the figure&#8217;s JavaFrame property (which Matlab has warned might be discontinued in some near upcoming release), which is sort of a handle reference to the Java window underlying the Matlab figure window (not exactly but close enough for today). We then travel up and down the JavaFrame window objects hierarchy (use my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj utility on the File Exchange</a> to understand this hierarchy) until we get to the status bar object. We then set its text and make it visible (it&#8217;s invisible by default). Here is a trimmed-down version (excluding the necessary sanity checks, exception handling etc.):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternative #1 (hFig = requested figure's handle)</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jFigPanel = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'FigurePanelContainer'</span><span style="color: #080;">&#41;</span>;
jRootPane = jFigPanel.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>.<span style="">getRootPane</span>;
jRootPane = jRootPane.<span style="">getTopLevelAncestor</span>;
statusbarObj = jRootPane.<span style="">getStatusBar</span>;
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;
jRootPane.<span style="">setStatusBarVisible</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative #2</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jRootPane = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span>;
statusbarObj = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJStatusBar</span>;
jRootPane.<span style="">setStatusBar</span><span style="color: #080;">&#40;</span>statusbarObj<span style="color: #080;">&#41;</span>;
statusbarObj.<span style="">setText</span><span style="color: #080;">&#40;</span>statusText<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><br
/><div
class="wp-caption aligncenter" style="width: 309px"><img
alt="simple figure status-bar text message" src="http://undocumentedmatlab.com/images/statusbar2.png" title="simple figure status-bar text message" width="299" height="156" /><p
class="wp-caption-text">simple figure status-bar text message</p></div><br
/></center></p><h3><b><i>StatusBar</i></b> utility</h3><p>I&#8217;ve created a wrapper function, aptly called <b><i>statusbar</i></b>, encapsulating all the above with some additional error checking etc. I have posted <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14773"><b><i>statusbar</i></b> on the MathWorks File Exchange</a>. Readers are encouraged to look at this submission&#8217;s source code for examples of statusbar manipulation. Here are several usage examples:</p><p><center><br
/><div
class="wp-caption aligncenter" style="width: 460px"><a
href="http://undocumentedmatlab.com/images/statusbar.png" target="_blank"><img
alt="statusbar usage examples (click to see details)" src="http://undocumentedmatlab.com/images/statusbar.png" title="statusbar usage examples (click to see details)" width="450" height="163" /></a><p
class="wp-caption-text"><b><i>statusbar</i></b> usage examples (click to see details)</p></div><br
/></center></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><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/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><li><a
href='http://undocumentedmatlab.com/blog/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></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-status-bar-text/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Displaying hidden handle properties</title><link>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/</link> <comments>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/#comments</comments> <pubDate>Tue, 05 May 2009 23:03:55 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Hidden property]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[OuterPosition]]></category> <category><![CDATA[PixelBounds]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=237</guid> <description><![CDATA[I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab Handle Graphics (HG) is a great way to manipulate GUI objects. HG handles often have some undocumented hidden properties. One pretty well-known example is the <strong>JavaFrame</strong> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object.  We can use hidden properties just like any other handle property, using the built-in <b><i>get</i></b> and <b><i>set</i></b> functions.</p><p>But how can we know about these properties? Here are two methods to do so. Like the hidden properties, these two methods are themselves undocumented&#8230;</p><p>1. use the desktop&#8217;s hidden <strong>HideUndocumented</strong> property:</p><blockquote><pre><span style="color: #000000">set(0,</span><span style="color: #800080">'HideUndocumented','off'</span><span style="color: #000000">);</pre></blockquote><p>From now on, when displaying handle properties using <b><i>get</i></b> and <b><i>set</i></b> you&#8217;ll see the hidden properties.</p><p>Note that some of the properties might display a warning indication:</p><blockquote><pre><span style="color: #000000">>> get(gcf)</span>
	Alphamap = [ (1 by 64) double array]
	BackingStore = on
	CloseRequestFcn = closereq
	Color = [0.8 0.8 0.8]
	Colormap = [ (64 by 3) double array]
	CurrentAxes = []
	CurrentCharacter =
	CurrentKey =
	CurrentModifier = [ (1 by 0) cell array]
	CurrentObject = []
	CurrentPoint = [0 0]
	Dithermap<span style="color: #800000">Warning: figure Dithermap is no longer useful
 with TrueColor displays, and will be removed in a future release.</span>
 = [ (64 by 3) double array]
        ...
</pre></blockquote><p>2. Access the properties&#8217; definition in the handle&#8217;s class definition:</p><blockquote><pre><span style="color: #000000">>> ch = classhandle(handle(gcf));
>> props = get(ch,</span><span style="color: #800080">'Properties'</span><span style="color: #000000">);
>> propsVisibility = get(props,</span><span style="color: #800080">'Visible'</span><span style="color: #000000">)';
>> hiddenProps = props(strcmp(propsVisibility,</span><span style="color: #800080">'off'</span><span style="color: #000000">));
>> sort(get(hiddenProps,</span><span style="color: #800080">'Name'</span><span style="color: #000000">))</span>
ans =
    'ALimInclude'
    'ActivePositionProperty'
    'ApplicationData'
    'BackingStore'
    'Behavior'
    'CLimInclude'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'ExportTemplate'
    'HelpFcn'
    'HelpTopicKey'
    'HelpTopicMap'
    'IncludeRenderer'
    'JavaFrame'
    'OuterPosition'
    'PixelBounds'
    'PrintTemplate'
    'Serializable'
    'ShareColors'
    'UseHG2'
    'WaitStatus'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
</pre></blockquote><p>Different HG handles have different hidden properties. Not all these properties are useful. For example, I have found the <strong>PixelBounds</strong> property to be problematic &#8211; (it sometimes reports incorrect values!). Other properties (like <strong>Dithermap</strong> or <strong>ShareColors</strong>) are deprecated and display a warning wherever they are accessed.</p><p>But every so often we find a hidden property that can be of some actual benefit. Let&#8217;s take the figure handle&#8217;s <strong>OuterPosition</strong> property for example. It provides the figure&#8217;s external position values, including the space used by the window frame, toolbars etc., whereas the regular documented <strong>Position</strong> property only reports the <b>internal</b> bounds:</p><blockquote><pre><span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'pos'</span>)
ans =
   232   246   560   420
<span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'outer'</span>)
ans =
   228   242   568   502
</pre></blockquote><p>In future posts I will sometimes use such hidden properties. You can find the latest list by looking at this blog&#8217;s <a
href="http://undocumentedmatlab.com/blog/category/Hidden-property/" target="_blank">&#8220;Hidden property&#8221;</a> category page.</p><p>Note: Like the rest of Matlab&#8217;s undocumented items, all hidden properties are undocumented, unsupported and may well change in future Matlab releases so use them with care.</p><p>Did you find any useful hidden property? If so, then please leave your finding in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           tag
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-04 03:23:13 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/javaframe/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      1.835s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328350992; expires=Sun, 03-Feb-2013 10:23:12 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:23:13 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:23:13 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               176c0d7b5cb514c830876a97ff0619cc
Content-Encoding:   gzip
-->
