<?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>JavaFrame &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/javaframe/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 22 Mar 2017 22:05:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>MathWorks-solicited Java survey</title>
		<link>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mathworks-solicited-java-survey</link>
					<comments>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 22 Mar 2017 22:05:34 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[uifigure]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6866</guid>

					<description><![CDATA[<p>MathWorks is soliciting user feedbacks about the use of Java components in Matlab programs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey">MathWorks-solicited Java survey</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/mathworks-blogs-facelift" rel="bookmark" title="MathWorks blogs facelift">MathWorks blogs facelift </a> <small>MathWorks has just released a new look-&-feel for their blogs section. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Over the years I&#8217;ve reported numerous uses for integrating Java components and functionality in Matlab. As I&#8217;ve also <a href="/articles/adding-a-search-box-to-figure-toolbar#uifigure" rel="nofollow" target="_blank">recently reported</a>, MathWorks is apparently making a gradual shift away from standalone Java-based figures, toward browser-based web-enabled figures. <a href="/articles/password-and-spinner-controls-in-matlab-gui#warning" target="_blank">As I surmised</a> a few months ago, MathWorks has created dedicated surveys to solicit user feedbacks on the most important (and undocumented) non-compatible aspects of this paradigm change: one regarding users&#8217; use of the <a href="/articles/javacomponent" rel="nofollow" target="_blank"><i><b>javacomponent</b></i> function</a>, the other regarding the use of the figure&#8217;s <a href="/articles/tag/javaframe" target="_blank"><b>JavaFrame</b> property</a>:</p>
<ul>
<li>Survey regarding usage of the <i><b>javacomponent</b></i> function: <a href="http://www.mathworks.com/javacomponent" rel="nofollow" target="_blank">http://www.mathworks.com/javacomponent</a></li>
<li>Survey regarding usage of the <b>JavaFrame</b> property: <a href="http://www.mathworks.com/javaframe" rel="nofollow" target="_blank">http://www.mathworks.com/javaframe</a></li>
</ul>
<p>In MathWorks&#8217; words:</p>
<blockquote><p>
In order to extend your ability to build MATLAB apps, we understand you sometimes need to make use of undocumented Java UI technologies, such as the JavaFrame property. In response to your needs, we are working to develop documented alternatives that address gaps in our app building offerings.<br />
To help inform our work and plans, we would like to understand how you are using the JavaFrame property. Based on your understanding of how it is being used within your app, please take a moment to fill out the following survey. The survey will take approximately 1-2 minutes to finish.
</p></blockquote>
<p>I urge anyone who uses one or both of these features to let MathWorks know how you&#8217;re using them, so that they could incorporate that functionality into the core (documented) Matlab. The surveys are really short and to the point. If you wish to send additional information, please email George.Caia at mathworks.com.<br />
The more feedback responses that MathWorks will get, the better it will be able to prioritize its R&#038;D efforts for the benefit of all users, and the more likely are certain features to get a documented solution at some future release. If you don&#8217;t take the time now to tell MathWorks how you use these features in your code, don&#8217;t complain if and when they break in the future&#8230;</p>
<h3 id="uses">My personal uses of these features</h3>
<ul>
<li><b>Functionality:</b>
<ul>
<li>Figure: maximize/minimize/restore, enable/disable, always-on-top, toolbar controls, menu customizations (icons, tooltips, font, shortcuts, colors)</li>
<li>Table: sorting, filtering, grouping, column auto-sizing, cell-specific behavior (tooltip, context menu, context-sensitive editor, merging cells)</li>
<li>Tree control</li>
<li>Listbox: cell-specific behavior (tooltip, context menu)</li>
<li>Tri-state checkbox</li>
<li>uicontrols in general: various event callbacks (e.g. mouse hover/unhover, focus gained/lost)</li>
<li>Ability to add Java controls e.g. color/font/date/file selector panel or dropdown, spinner, slider, search box, password field</li>
<li>Ability to add 3rd-party components e.g. JFreeCharts, JIDE controls/panels</li>
</ul>
<p></li>
<li><b>Appearance:</b>
<ul>
<li>Figure: undecorated (frameless), other figure frame aspects</li>
<li>Table: column/cell-specific rendering (alignment, icons, font, fg/bg color, string formatting)</li>
<li>Listbox: auto-hide vertical scrollbar as needed, cell-specific renderer (icon, font, alignment, fg/bg color)</li>
<li>Button/checkbox/radio: icons, text alignment, border customization, Look &#038; Feel</li>
<li>Right-aligned checkbox (button to the right of label)</li>
<li>Panel: border customization (rounded/matte/&#8230;)</li>
</ul>
</li>
</ul>
<p>You can find descriptions/explanations of many of these in posts I made on this website over the years.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey">MathWorks-solicited Java survey</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/mathworks-blogs-facelift" rel="bookmark" title="MathWorks blogs facelift">MathWorks blogs facelift </a> <small>MathWorks has just released a new look-&-feel for their blogs section. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Figure window customizations</title>
		<link>https://undocumentedmatlab.com/articles/figure-window-customizations?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=figure-window-customizations</link>
					<comments>https://undocumentedmatlab.com/articles/figure-window-customizations#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 01 Jun 2016 08:00:11 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6439</guid>

					<description><![CDATA[<p>Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/figure-window-customizations">Figure window customizations</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/figure-toolbar-customizations" rel="bookmark" title="Figure toolbar customizations">Figure toolbar customizations </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A friend recently asked me, in light of <a href="/articles/adding-a-search-box-to-figure-toolbar#uifigure" target="_blank">my guesstimate</a> that Java-based Matlab figures will be replaced by web-based figures sometime around 2018-2020, whether there are any &#8220;killer features&#8221; that make it worthwhile to use undocumented Java-based tricks today, despite the fact that they will probably break in 2-5 years. In my opinion, there are many such features; today I will focus on just a subset of them &#8211; those features that relate to the entire figure window.<br />
Over the years I wrote many articles here about <a href="/articles/tag/javaframe" target="_blank">figure-level customizations</a>, as well as an entire chapter in my <a href="/books/matlab-java" target="_blank">Matlab-Java programming book</a>. So today&#8217;s post will be a high-level overview, and users who are interested in any specific topic can visit the referenced links for the implementation details.<br />
<center><img decoding="async" alt="An undecorated Matlab figure window - one of many possible figure-level customizations" src="https://undocumentedmatlab.com/images/undecorated_figure.gif" title="An undecorated Matlab figure window - one of many possible figure-level customizations" width="80%" style="max-width: 616px;" /><br />An undecorated Matlab figure window &#8211; one of many possible figure-level customizations</center><br />
<span id="more-6439"></span></p>
<h3 id="JavaFrame">JavaFrame</h3>
<p><a href="/articles/minimize-maximize-figure-window/#JavaFrame" target="_blank"><b>JavaFrame</b></a> is an undocumented hidden property of the figure handle that provides access to the underlying Java window (<code>JFrame</code>) peer object&#8217;s reference. Since R2008a, a warning is issued whenever we retrieve this property:</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.)
</pre>
</div>
</div>
<p>Until HG2 (R2014b+) we could suppress the warning by simply wrapping the figure handle within a <i><b>handle()</b></i> call, as <a href="/articles/minimize-maximize-figure-window/#JavaFrame" target="_blank">explained here</a>. Since R2014b we need to use the <i><b>warning</b></i> function to do this:</p>
<pre lang="matlab">warning('off', 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');</pre>
<p>We can do several things directly with the <b>JavaFrame</b>&#8216;s properties and methods, including:</p>
<ul>
<li>Maximize/minimize/restore the window, via the properties <b>Maximized</b>/<b>Minimized</b> (which accept and return a boolean (logical) value), or the corresponding methods <i>jFrame.isMaximized(), isMinimized(), setMaximized(flag), setMinimized(flag)</i>. <a href="/articles/minimize-maximize-figure-window" target="_blank">details</a></li>
<li>Modify the container to which the figure will be docked. By default this is the &#8220;Figures&#8221; container, but this can be changed to any user-specified container, or even to the &#8220;Editor&#8221;, using the <b>GroupName</b> property or its associated methods. See the related <a href="http://www.mathworks.com/matlabcentral/fileexchange/16650-setfigdockgroup" rel="nofollow" target="_blank"><i><b>setFigDockGroup</b></i> utility</a> that I posted on the Matlab File exchange.</li>
<li>Remove the top separator line between the toolbar and the content-pane, to blend them together, via the <i>jFrame.showTopSeparator(flag)</i> method.</li>
<li>Retrieve a direct Java reference to the Matlab Desktop and the figure&#8217;s internal containers via the <b>Desktop</b> and <b>FigurePanelContainer</b> properties, respectively (we can also get those references by other means).</li>
<li>Retrieve a direct Java reference to the containing <code>JFrame</code> (Java window), as discussed below</li>
<li>A few other features that I will not discuss here</li>
</ul>
<p>MathWorks have set up a dedicated webpage where you can specify how you are using <b>JavaFrame</b> and why it is important for you: <a href="http://www.mathworks.com/javaframe" rel="nofollow" target="_blank">http://www.mathworks.com/javaframe</a>. I encourage you to use this webpage to tell MathWorks which features are important for you. This will help them to decide which functionality should be added to the new web-based figures.</p>
<h3 id="JFrame">JFrame window</h3>
<p>The <b>JavaFrame</b> handle enables direct retrieval of the containing Java <a href="https://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html" rel="nofollow" target="_blank"><code>JFrame</code></a> (window) reference, using several alternatives. Here are two of these alternatives (there are others):</p>
<pre lang="matlab">
% Alternative #1
>> jWindow = jFrame.getFigurePanelContainer.getTopLevelAncestor
jWindow =
com.mathworks.hg.peer.FigureFrameProxy$FigureFrame[fClientProxyFrame,72,62,576x507,...]
% Alternative #2
try
    jClient = jFrame.fFigureClient;  % This works up to R2011a
catch
    try
        jClient = jFrame.fHG1Client;  % This works from R2008b-R2014a
    catch
        jClient = jFrame.fHG2Client;  % This works from R2014b and up
    end
end
jWindow = jClient.getWindow;
</pre>
<p><figure style="width: 400px" class="wp-caption alignright"><img decoding="async" alt="Customized menu items" src="https://undocumentedmatlab.com/images/uimenu1.png" title="Customized menu items" width="202" height="200" /> <img decoding="async" src="https://undocumentedmatlab.com/images/uimenu7a.png" alt="Customized menu items" title="Customized menu items" width="160" height="180" /><br />
<img fetchpriority="high" decoding="async" src="https://undocumentedmatlab.com/images/statusbar_animated.gif" alt="Integrated figure status bar" title="Integrated figure status bar" width="400" height="253" /><figcaption class="wp-caption-text">Customized menu items (top) and figure status bar (bottom)</figcaption></figure>With the retrieved <code>jWindow</code> reference, we can do several additional interesting things:</p>
<ul>
<li>Enable/disable the entire figure in a single go (<a href="/articles/disable-entire-figure-window" target="_blank">details</a>)</li>
<li>Remove/restore the window frame (borders and title bar), otherwise known as an &#8220;undecorated window&#8221; (<a href="/articles/frameless-undecorated-figure-windows" target="_blank">details</a>)</li>
<li>Set the figure window to be &#8220;Always-On-Top&#8221;, i.e. not occluded by any other window, via the <b>AlwaysOnTop</b> property, or the corresponding <i>jWindow.isAlwaysOnTop(), setAlwaysOnTop(flag)</i> methods.</li>
<li>Make the figure window fully or partially transparent (<a href="/articles/transparent-matlab-figure-window" target="_blank">details</a>). Note: this fails on R2013b/Java7 and higher due to a change in the way that transparency works in Java 7 compared to earlier releases; in other words blame Oracle&#8217;s Java, not MathWorks&#8217; Matlab&#8230;.</li>
<li>Blur/restore the figure window (<a href="/articles/blurred-matlab-figure-window" target="_blank">details</a>). This too works only up to R2013a.</li>
<li>Detect and handle window-level focus gain/loss events (<a href="/articles/detecting-window-focus-events" rel="nofollow" target="_blank">details</a>), as well as window-level mouse events (enter/exit/hover etc. &#8211; <a href="/articles/matlab-callbacks-for-java-events-in-r2014a" target="_blank">details</a>).</li>
<li>Customize the figure&#8217;s menu bar &#8211; dynamic behavior, tooltips, highlights, keyboard shortcuts/accelerators, font colors/styles, callbacks, icons etc. (<a href="/articles/customizing-menu-items-part-2" target="_blank">details1</a>, <a href="/articles/customizing-menu-items-part-3" target="_blank">details2</a>)</li>
<li>Control figure docking in compiled (deployed) applications (<a href="/articles/docking-figures-in-compiled-applications" target="_blank">details1</a>, <a href="/articles/disabling-menu-entries-in-deployed-docked-figures" target="_blank">details2</a>)</li>
<li>Display an integral figure status-bar with text and GUI controls (<a href="/articles/setting-status-bar-text" target="_blank">details1</a>, <a href="/articles/setting-status-bar-components" target="_blank">details2</a>).</li>
<li>A few other features that I will not discuss here</li>
</ul>
<p>As you can see, there are numerous very interesting customizations that can be done to Matlab figures which rely on the undocumented implementation. Here are a couple of usage examples that you can easily adapt (follow the links above for additional details and usage examples):</p>
<pre lang="matlab">
jWindow.setEnabled(false);     % disable entire figure [true/false]
jWindow.setMinimized(true);    % minimize window [true/false]
jWindow.setMaximized(true);    % maximize window [true/false]
jWindow.setAlwaysOnTop(true);  % set to be always on top [true/false]
% Set a Matlab callback function to a window focus-gain event
hjWindow = handle(jWindow, 'CallbackProperties');
hjWindow.FocusGainedCallback = @myCallbackFunc;
</pre>
<p>In addition to the Java-based features above, some functionalities can also be achieved via direct OS manipulations, for example using Jan Simon&#8217;s great <a href="http://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi" rel="nofollow" target="_blank">WindowAPI utility</a> (Windows-only), although I typically prefer using the Java approach since it is cross-platform compatible.<br />
Using all these features is super-easy, so there is not really a question of code complexity or technical risk &#8211; the main question is whether to accept the risk that the associated code will stop working when Matlab figures will eventually become web-based.</p>
<h3 id="risk">So is it worth the risk?</h3>
<p>This is an excellent question. I contend that the answer depends on the specific use-case. In one project you may decide that it is indeed worth-while to use these undocumented features today, whereas in another GUI you may decide that it is not.<br />
It might make sense to use the features above in any of the following circumstances:</p>
<ul>
<li>If you need any of the features in your Matlab GUI today. In this case, you really have no alternative other than to use these features, since there is no documented way to achieve the required functionality.</li>
<li>If you do not plan to upgrade your Matlab release soon, or at least after the Java-based figures are discontinued in a few years. The commercial Matlab license is perpetual, enabling users to enjoy these features for as long as they continue using this Matlab release.</li>
<li>If you are compiling your Matlab program using the Matlab Compiler or Coder toolboxes. In such cases, the executable will remain static, until such time (if ever) that you decide to recompile it using a newer Matlab release. Users of the compiled code could continue to use the compiled undocumented features well into the future, for as long as their computers keep running. In such cases, we are not concerned with release compatibility issues.</li>
<li>If you accept the risk that some recoding may be necessary in the future, or that some functionality will degrade, for the added benefit that they provide your GUIs today.</li>
<li>If you are willing to code without MathWorks&#8217; official support and endorsement, and accept the fact that they will not fix any internal bugs that you may discover which is related to these features.</li>
<li>If you wish to present a professional-grade GUI today, and worry about potential incompatibilities only if and when they eventually arrive, sometime in the future.</li>
</ul>
<p>Here&#8217;s another twist to consider: do <b>not</b> take it for granted that when web-based uifigures replace Java-based figures all the documented functionality will work as-is on the new uifigures just as they have on the old figures. In fact, I personally believe that we will need to extensively modify our GUI code to make it compatible with the new uifigures. In other words, avoiding the undocumented hacks above will probably not save us from the need to recode (or at least adapt) our GUI, it will just reduce the necessary work somewhat. We encountered a similar situation with the graphics hacks that I exposed over the years: many people avoided them in the fear that they might someday break; then when R2014b came and HG2 graphics replaced HG1, it turned out that many of these supposedly risky hacks continued working in HG2 (examples: <a href="/articles/axes-looseinset-property" target="_blank">LooseInset</a>, <a href="/articles/plot-liminclude-properties" target="_blank">YLimInclude</a>) whereas quite a bit of standard fully-documented Matlab functionality was broken and required some recoding. I believe that the lessons from the HG2 migration were well studied and assimilated by MathWorks, but realistically speaking we should not expect a 100% full-proof transition to uifigures.<br />
Still, accepting the risk does not mean that we should bury our head in the sand. Whenever using any undocumented feature in your code, I strongly suggest to use defensive coding practices, such as wrapping your code within <i><b>try-catch</b></i> blocks. This way, even if the feature is removed in R2020a (or whenever), the program will still run, albeit with somewhat diminished functionality, or in other words, <i>graceful degradation</i>. For example:</p>
<pre lang="matlab">
try
    jFrame = get(hFig, 'JavaFrame');
    jFrame.setMaximized(true);
catch
    oldUnits = get(hFig, 'Units');
    set(hFig, 'Units','norm', 'Pos',[0,0,1,1]);
    set(hFig, 'Units',oldUnits);
end
</pre>
<p>Once again, I urge you to visit <a href="http://www.mathworks.com/javaframe" rel="nofollow" target="_blank">http://www.mathworks.com/javaframe</a> and tell MathWorks which of the above features are important for you. The more users tell MathWorks that they depend on a specific feature, the more would MathWorks be likely to invest R&#038;D efforts in enabling it in the future web-based figures.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/figure-window-customizations">Figure window customizations</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/figure-toolbar-customizations" rel="bookmark" title="Figure toolbar customizations">Figure toolbar customizations </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/figure-window-customizations/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Faster findjobj</title>
		<link>https://undocumentedmatlab.com/articles/faster-findjobj?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=faster-findjobj</link>
					<comments>https://undocumentedmatlab.com/articles/faster-findjobj#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 11 Apr 2016 09:18:14 +0000</pubDate>
				<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[FindJObj]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6376</guid>

					<description><![CDATA[<p>the ubiquitous findjobj utility has been significantly improved for speed for the most common use case. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/faster-findjobj">Faster findjobj</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/faster-csvwrite-dlmwrite" rel="bookmark" title="Faster csvwrite/dlmwrite">Faster csvwrite/dlmwrite </a> <small>The speed of the builtin csvwrite, dlmwrite functions can be improved dramatically. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>My <a href="/articles/findjobj-find-underlying-java-object" target="_blank"><i><b>findjobj</b></i> utility</a>, created in 2007 and updated over the years, has received wide recognition and is employed by numerous Matlab programs, including a few dozen utilities in the Matlab File Exchange. I am quite proud of this utility and find it extremely useful for customizing Matlab controls in many ways that are impossible using standard Matlab properties. I have shown <a href="/?s=findjobj" target="_blank">many examples of this</a> in this blog over the past years.<br />
I am happy to announce that I have just uploaded a new version of <i><b>findjobj</b></i> to the <a href="http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects" rel="nofollow" target="_blank">Matlab File Exchange</a>, which significantly improves the utility&#8217;s performance for the most common use-case of a single input and a single output, namely finding the handle of the underlying Java component (peer) of a certain Matlab control:</p>
<pre lang="matlab">
>> hButton = uicontrol('String','click me!');
>> tic, jButton = findjobj(hButton); toc  % old findjobj
Elapsed time is 1.513217 seconds.
>> tic, jButton = findjobj(hButton); toc  % new findjobj
Elapsed time is 0.029348 seconds.
</pre>
<p>The new <i><b>findjobj</b></i> is backward-compatible with the old <i><b>findjobj</b></i> and with all prior Matlab releases. It is a drop-in replacement that will significantly improve your program&#8217;s speed.<br />
The new version relies on several techniques:<span id="more-6376"></span><br />
First, as I <a href="/articles/customizing-matlab-uipanels" rel="nofollow" target="_blank">showed last year</a>, in HG2 (R2014 onward), Matlab <i><b>uipanel</b></i>s have finally become full-featured Java <code>JPanel</code>s, that can be accessed and customized in many interesting manners. More to the point here, we can now directly access the underlying <code>JPanel</code> component handle using the <i><b>uipanel</b></i>&#8216;s hidden <b>JavaFrame</b> property (thanks to MathWorks for supplying this useful hook!). The new <i><b>findjobj</b></i> version detects this and immediately returns this handle if the user specified a <i><b>uipanel</b></i> input.<br />
I still do not know of any direct way to retrieve the underlying Java component&#8217;s handle for Matlab <i><b>uicontrol</b></i>s, this has been a major frustration of mine for quite a few years. So, we need to find the containing Java container in which we will recursively search for the control&#8217;s underlying Java handle. In the old version of <i><b>finjobj</b></i>, we retrieve the containing figure&#8217;s <code>JFrame</code> reference and from it the <code>ContentPane</code> handle, and use this handle as the Java container that is recursively searched. This is quite slow when the figure window is heavily-laden with multiple controls. In the new version, we try to use the specified Matlab <i><b>uicontrol</b></i>&#8216;s direct parent, which is very often a <i><b>uipanel</b></i>. In this case, we can directly retrieve the panel&#8217;s <code>JPanel</code> reference as explained above. This results in a must smaller and faster search since we need to recursively search far fewer controls within the container, compared to the figure&#8217;s <code>ContentPane</code>.<br />
In addition, I used a <a href="/articles/findjobj-gui-display-container-hierarchy#comment-332487" target="_blank">suggestion</a> by blog reader Hannes for a faster recursive search that uses the control&#8217;s tooltip rather than its size, position and class. Finally, the search order is reversed to search backward from the last child component, since this is the component that will most often contain the requested control peer.<br />
Feel free to download and use the new <i><b>findjobj</b></i> version. The code for the fast variant can be found in lines #190-205 and #3375-3415.<br />
Enjoy!<br />
p.s. &#8211; as I explained last week, today&#8217;s discussion, and in general anything that has to do with Java peers of GUI controls, only relates to the existing <code>JFrame</code>-based figure windows, not to the new web-based <i><b>uifigure</b></i>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/faster-findjobj">Faster findjobj</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/faster-csvwrite-dlmwrite" rel="bookmark" title="Faster csvwrite/dlmwrite">Faster csvwrite/dlmwrite </a> <small>The speed of the builtin csvwrite, dlmwrite functions can be improved dramatically. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/faster-findjobj/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Frameless (undecorated) figure windows</title>
		<link>https://undocumentedmatlab.com/articles/frameless-undecorated-figure-windows?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=frameless-undecorated-figure-windows</link>
					<comments>https://undocumentedmatlab.com/articles/frameless-undecorated-figure-windows#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 19 Mar 2015 22:00:37 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5642</guid>

					<description><![CDATA[<p>Matlab figure windows can be made undecorated (borderless, title-less). </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/frameless-undecorated-figure-windows">Frameless (undecorated) figure windows</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/figure-window-customizations" rel="bookmark" title="Figure window customizations">Figure window customizations </a> <small>Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>All Matlab figures have a standard frame around them, consisting of a border and title bar. In some cases it could be useful to present a figure window, displaying only the contents without the border and title bar. Such a borderless (undecorated) window is not possible in Matlab. Well, at least not in supported/documented Matlab&#8230;<br />
Readers of this blog and/or my <a target="_blank" href="/books/matlab-java">Matlab-Java programming book</a> are aware that Matlab&#8217;s GUI is based on Java Swing. In the end, every Matlab figure window is a simple Java <code><a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html">JFrame</a></code>, and JFrames have a <i>setUndecorated(true)</i> method that can be called to remove the border and title bar.<br />
<center><img decoding="async" alt="An undecorated Matlab figure window" src="https://undocumentedmatlab.com/images/undecorated_figure.gif" title="An undecorated Matlab figure window" width="80%" style="max-width: 616px;" /><br />An undecorated Matlab figure window</center><br />
<span id="more-5642"></span></p>
<h3 id="1">Attempt #1 &#8211; direct invocation</h3>
<p>Unfortunately, we cannot directly call <i>setUndecorated</i> in Matlab, because it only works when the <code>JFrame</code> has not yet been displayed:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Get the figure's underlying Java JFrame reference handle</span>
&gt;&gt; mjf = <span style="color: #0000FF;">get</span><span style="color: #080;">(</span>handle<span style="color: #080;">(</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">)</span>, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">)</span>;
&gt;&gt; jWindow = mjf.fHG2Client.getWindow  <span style="color: #228B22;">% or: mjf.getAxisComponent.getTopLevelAncestor</span>
jWindow =
com.mathworks.hg.peer.FigureFrameProxy$FigureFrame[fClientProxyFrame,740,-761,576x509,...]
&nbsp;
<span style="color: #228B22;">% Try to remove decoration</span>
&gt;&gt; jWindow.setUndecorated(<span style="color: #0000FF;">true</span>)
<span style="color: #F00;">Java exception occurred:
java.awt.IllegalComponentStateException: The frame is displayable.
	at java.awt.Frame.setUndecorated(Unknown Source)</span></pre>
</div>
</div>
<p>On the other hand, if we try to call <i>setUndecorated</i> on a new invisible figure then we&#8217;d see that the <code>JFrame</code> component is not yet created by Matlab:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create a simple Matlab figure</span>
hFig = <span style="color: #0000FF;">figure</span><span style="color: #080;">(</span><span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'Plot example'</span>, <span style="color:#A020F0;">'Visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">)</span>;
&nbsp;
<span style="color: #228B22;">% Get the underlying Java JFrame reference handle (empty)</span>
&gt;&gt; mjf = <span style="color: #0000FF;">get</span><span style="color: #080;">(</span>handle<span style="color: #080;">(</span>hFig<span style="color: #080;">)</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">)</span>;
&gt;&gt; jWindow = mjf.getAxisComponent.getTopLevelAncestor
jWindow =
     <span style="color: #080;">[</span><span style="color: #080;">]</span>
&gt;&gt; jWindow = mjf.fHG2Client.getWindow
jWindow =
     <span style="color: #080;">[</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; jWindow.setUndecorated<span style="color: #080;">(</span><span style="color: #0000FF;">true</span><span style="color: #080;">)</span>
<span style="color: #F00;">Attempt to reference field of non-structure array.</span></pre>
</div>
</div>
<p>So we have a catch-22 situation: we can&#8217;t call <i>setUndecorated</i> until the <code>JFrame</code> is created, but Matlab only creates it when it displays the figure window, and then it&#8217;s too late to undecorate&#8230;</p>
<h3 id="2">Attempt #2 &#8211; reparenting: an optical illusion</h3>
<p>One way that I found around this problem is to reparent the Matlab <code>JFrame</code>&#8216;s content onto a pure Java <code>JFrame</code> that has been made undecorated. To hide the Matlab figure after creating the <code>JFrame</code>, we can simply move the figure&#8217;s position to be outside the visible monitor area:</p>
<pre lang='matlab'>
% Create a simple Matlab figure (visible, but outside monitor area)
t = 0 : 0.01 : 10;
hFig = figure('Name','Plot example', 'ToolBar','none', 'MenuBar','none');
hLine = plot(t, cos(t));
hButton = uicontrol('String','Close', 'Position',[307,0,45,16]);
% Ensure that everything is rendered, otherwise the following will fail
drawnow;
% Get the underlying Java JFrame reference handle
mjf = get(handle(hFig), 'JavaFrame');
jWindow = mjf.fHG2Client.getWindow;  % or: mjf.getAxisComponent.getTopLevelAncestor
% Get the content pane's handle
mjc = jWindow.getContentPane;
mjr = jWindow.getRootPane;  % used for the offset below
% Create a new pure-Java undecorated JFrame
figTitle = jWindow.getTitle;
jFrame = javaObjectEDT(javax.swing.JFrame(figTitle));
jFrame.setUndecorated(true);
% Move the JFrame's on-screen location just on top of the original
jFrame.setLocation(mjc.getLocationOnScreen);
% Set the JFrame's size to the Matlab figure's content size
%jFrame.setSize(mjc.getSize);  % slightly incorrect by root-pane's offset
jFrame.setSize(mjc.getWidth+mjr.getX, mjc.getHeight+mjr.getY);
% Reparent (move) the contents from the Matlab JFrame to the new JFrame
jFrame.setContentPane(mjc);
% Make the new JFrame visible
jFrame.setVisible(true);
% Hide the Matlab figure by moving it off-screen
pos = get(hFig,'Position');
set(hFig, 'Position',[-1000,-1000,pos(3:4)]);
drawnow;
</pre>
<p>Matlab figures are not pure <code>JFrame</code> but rather a subclass (<code>com.mathworks.widgets.desk.DTSingleClientFrame</code>). So instead of creating a new <code>JFrame</code>, we could create a new instance of Matlab&#8217;s class instead, potentially solving a few problems:</p>
<pre lang='matlab'>
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jFrame = javaObjectEDT(com.mathworks.widgets.desk.DTSingleClientFrame(jDesktop, figTitle));
% ...the rest is exactly the same as above...
</pre>
<p>Either way, we now get a nice undecorated window containing our Matlab contents (see screenshot above).<br />
Once the undecorated <code>JFrame</code> becomes visible, we should not hide or delete the original Matlab figure, because this will stop rendering of the contents.</p>
<h3 id="customizing">Working with the undecorated frame</h3>
<p>We can modify the Matlab figure and its contents normally, just as if they still appeared within the original Matlab figure. This can be used to display a dynamic application splash-screen, that displays information on various initialization/loading steps. Or alternately we could use it to display a system health-monitor (small panel with red/green indicators), or maybe a graph with streaming market data or live news alerts. The usages are endless, limited only by your imagination, <u>not</u> by Matlab.<br />
For example, let&#8217;s modify our plot dynamically using a timer, and set the close button&#8217;s callback to dismiss the new <code>JFrame</code> and original figure:</p>
<pre lang='matlab'>
% Set a timer to dynamically update the plot every 0.1 sec
start(timer('TimerFcn', {@timerCallback,hLine}, 'ExecutionMode','fixedRate', 'Period',0.1));
% Set the close button callback
set(hButton, 'Callback',{@closeCallback,jFrame});
% This is the close button's callback
function closeCallback(hButton, eventData, jFrame)
   delete(ancestor(hButton,'figure'));
   dispose(jFrame);
end
% This is the plot timer's callback
function timerCallback(hTimer, eventData, hLine)
   xdata = get(hLine,'XData') + 0.1;
   set(hLine, 'XData',xdata, 'YData',cos(xdata));
   xlim([min(xdata) max(xdata)]);
end
</pre>
<p>Note: if you don&#8217;t hide the toolbar/menubar in the original Matlab figure, some of their functions will not work properly in the new <code>JFrame</code> (e.g., zoom, pan etc.). But in most use-cases we do not want a toolbar/menubar in an undecorated window. The example above showed an undecorated window without the toolbar/menubar.<br />
If we wish to avoid having the new <code>JFrame</code> appear in the Operating System&#8217;s taskbar, we can use the following command:</p>
<pre lang='matlab'>jFrame.setType(javaMethod('valueOf','java.awt.Window$Type','UTILITY'))</pre>
<p>Note that this command must be executed <u>before</u> the <code>JFrame</code> is made visible. Also note that it only works with Java 7, in other words Matlab R2013b (8.2) or newer (or if you are very adventurous and happen to use an older Matlab with a custom Java 7 installation).<br />
But now that there is no taskbar component, how can we transfer focus to our new undecorated window? In other words, if another windows hides our new undecorated frame, how can we get it back on top?<br />
A simple solution is to set the Matlab figure frame&#8217;s <b>FocusGainedCallback</b> to <i>requestFocus</i> for the newly created <code>jFrame</code>. Then, when we click the Matlab figure&#8217;s button on the taskbar, the new <code>jFrame</code> will pop into focus. In effect, this provides the optical illusion that the taskbar button refers to the undecorated window (since the actual Matlab figure is positioned beyond the monitor&#8217;s area):</p>
<pre lang='matlab'>
hjWindow = handle(jWindow, 'CallbackProperties');
set(hjWindow, 'FocusGainedCallback', @(h,e)jFrame.requestFocus);
</pre>
<p>Likewise, we should instrument our Matlab figure so that when it is closed/deleted, so too is our new <code>jFrame</code>:</p>
<pre lang='matlab'>set(hjWindow, 'WindowClosedCallback', @(h,e)jFrame_.dispose);</pre>
<h3 id="undecorateFig">undecorateFig and redecorateFig</h3>
<p>I have encapsulated all of the above in a couple of very easy-to-use utilities that I just <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/50111-undecoratefig-remove-restore-figure-border-and-title-bar">posted on the Matlab File Exchange</a>: <i><b>undecorateFig</b></i>, <i><b>redecorateFig</b></i>. Using them can&#8217;t get any simpler than this:</p>
<pre lang='matlab'>
undecorateFig;        % undecorate the current figure (gcf)
undecorateFig(hFig);  % hFig is any GUI handle (needs to be visible)
redecorateFig;        % redecorate the current figure (gcf)
redecorateFig(hFig);  % hFig is any GUI handle
</pre>
<blockquote><p>Any sufficiently advanced technology is indistinguishable from magic – Arthur C. Clarke &nbsp; 🙂</p></blockquote>
<p>Have you made some interesting use of this nice feature in your application? If so, please share it in a comment below.<br />
A suggested related mini project for anyone interested: add an <a target="_blank" rel="nofollow" href="http://google.com/search?q=reflection&#038;tbm=isch">image reflection</a> of the current figure contents beneath the figure. You could use my <a target="_blank" href="/articles/screencapture-utility"><i><b>ScreenCapture</b></i></a> utility or directly use <a target="_blank" rel="nofollow" href="http://www.java2s.com/Code/JavaAPI/java.awt/RobotcreateScreenCaptureRectanglescreenRect.htm"><code>java.awt.Robot.createScreenCapture(mjc.getLocationOnScreen)</code></a>, process the resulting image (blur, apply transparency gradient, crop at 50% height etc.) and place the resulting image within an undecorated <code>JFrame</code> placed directly beneath the main figure. You can instrument the figure (<code>hjWindow</code>)&#8217;s <b>ComponentMovedCallback</b> and <b>ComponentResizedCallback</b> to move/resize the reflection <code>JFrame</code> whenever the parent figure moves or is resized. You could use a timer to periodically update the reflection image so that it remains synchronized with the parent. You&#8217;ll probably also want to add a nice toggle-button to the figure&#8217;s toolbar to turn the reflection on/off. Maybe I&#8217;ll hack this project someday when I have some spare time. Or maybe someone will beat me to it&#8230; Care to try?</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/frameless-undecorated-figure-windows">Frameless (undecorated) figure windows</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/figure-window-customizations" rel="bookmark" title="Figure window customizations">Figure window customizations </a> <small>Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/frameless-undecorated-figure-windows/feed</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Waterloo graphics beta</title>
		<link>https://undocumentedmatlab.com/articles/waterloo-graphics-beta?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=waterloo-graphics-beta</link>
					<comments>https://undocumentedmatlab.com/articles/waterloo-graphics-beta#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 26 Jun 2013 18:00:20 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Malcolm Lidierth]]></category>
		<category><![CDATA[Waterloo]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3907</guid>

					<description><![CDATA[<p>The Waterloo graphics library extends Matlab graphics with numerous customizable plots that can be embedded in Matlab figures. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/waterloo-graphics-beta">Waterloo graphics beta</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics-examples" rel="bookmark" title="Waterloo graphics examples">Waterloo graphics examples </a> <small>Some Matlab usage examples for the open-source Waterloo graphics package. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics-animation-web-deployment" rel="bookmark" title="Waterloo graphics animation and web deployment">Waterloo graphics animation and web deployment </a> <small>Waterloo graphics can be updated very quickly in Matlab, enabling plot animation; web deployment of the graphics is also possible. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics" rel="bookmark" title="Waterloo graphics">Waterloo graphics </a> <small>Waterloo is an open-source library that can significantly improve Matlab GUI. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-hg2-graphics-events" rel="bookmark" title="Undocumented HG2 graphics events">Undocumented HG2 graphics events </a> <small>Matlab's new HG2 graphics engine includes many new undocumented events that could be used in various ways. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I&#8217;d like to welcome guest blogger <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/23816">Malcolm Lidierth</a> of King’s College London. Malcolm has written several articles here, including a <a target="_blank" href="/articles/waterloo-graphics/">couple of articles</a> on his Waterloo graphing library. Today, Malcolm discusses new features in this library, as it matures into an official beta phase.</i><br />
<center><figure style="width: 295px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Waterloo contour plot of Matlab's penny image" src="https://undocumentedmatlab.com/images/lincoln.jpg" title="Waterloo contour plot of Matlab's penny image" width="295" height="284" /><figcaption class="wp-caption-text">Waterloo contour plot of Matlab's penny image</figcaption></figure></center> Last year, Yair kindly allowed me space for a couple of guest blogs on the <a target="_blank" rel="nofollow" href="http://sourceforge.net/projects/waterloo/">Waterloo graphics</a> open-source project. Waterloo has recently transitioned to a &#8216;beta&#8217; release status, with several new features – many of them in response to suggestions from readers of this blog. Many thanks to all who made those.<br />
One of the motivations in writing Waterloo was to get better, less pixellated graphs in Matlab. By using Java 2D, the core library is not tied to Matlab. Waterloo graphics can be used wherever there is access to a Java Virtual Machine: R, ScilLab etc. MathWorks obviously feel the need for better graphics too: Yair recently blogged about the <a target="_blank" href="/articles/hg2-update/">next generation Matlab graphics (HG2)</a>. The Waterloo beta release provides support for mixing both Waterloo graphs and Matlab HG2 graphs in a single figure (as well as current HG1 graphics of course).<br />
The new features in the Waterloo beta can be summarized as:</p>
<ol>
<li>Introducing new plot types: contours, bars, polar and area charts</li>
<li>Mouse-selectable regions of interest</li>
<li>Support for fast-plot updates without redrawing the entire graph</li>
<li>Support for web-deployment of the graphs using <a target="_blank" rel="nofollow" href="http://www.w3.org/Graphics/SVG/">SVG</a> or <a target="_blank" rel="nofollow" href="http://www.processing.org">Processing</a> and <a target="_blank" rel="nofollow" href="http://processingjs.org">ProcessingJS</a></li>
</ol>
<p>Today I will concentrate on [1] and [2], illustrated with some Matlab examples; I will discuss [3] and [4] next week.<br />
<span id="more-3907"></span></p>
<h3 id="installation">Installation of Waterloo in Matlab</h3>
<p>For those readers who have not yet installed Waterloo in Matlab, the process is very simple: download the <a target="_blank" rel="nofollow" href="http://sourceforge.net/projects/waterloo/files/latest/download">latest zip file</a> and extract it. All the sub-folders in the <i>waterloo</i> folder are needed but only the <i>Waterloo_MATLAB_Library</i> subfolder (not its subfolders) should be added to the Matlab path. Once installed, just type <i><b>waterloo</b></i> at the Matlab prompt in each Matlab session.<br />
A Matlab script file that will do it all is available here (<a target="_blank" href="/files/Waterloo_installer.m">Waterloo_installer.m</a>). The script is harmless to run if you already have Waterloo installed, but if not then it will automatically find the latest zip file on SourceForge, download and install it, and then configure the Matlab path appropriately.</p>
<h3 id="contour">Contour plots</h3>
<p>I ended my <a target="_blank" href="/articles/waterloo-graphics-examples/">last guest article</a> with an example of work-in-progress: filled contours. The beta release now fully supports these.<br />
Recall from the <a target="_blank" href="/articles/waterloo-graphics/">previous articles</a> that <code>GXFigure</code> creates a Waterloo-compatible Matlab figure window. <i>gxgca()</i> returns a reference to the container for the graph as a Matlab <code>GXGraph</code> object, much as Matlab&#8217;s built-in <i><b>gca</b></i> returns an axes reference.<br />
Here is Matlab&#8217;s Lincoln penny demo in Waterloo:</p>
<pre lang='matlab'>
% Get some pre-defined colors
colors = [kcl.waterloo.defaults.Colors.getColor(0)];
for k = 1 : 17
    colors = horzcat(colors,kcl.waterloo.defaults.Colors.getColor(k));
end
f = GXFigure();
set(gcf, 'Name','Filled Contour', 'Units','normalized', 'Position',[0.3 0.3 0.4 0.4])
load penny;
ax = subplot(f,1,1,1);
ax.getObject().setAspectRatio(1);
p2 = contourf(ax, flipud(P), 18, 'LineStyle','-', 'LineWidth',0.4);
p2.getObject().setFillClipping(false);
p2.getObject().setFill(colors);
drawnow();
</pre>
<p>(resulting in the contour plot above)<br />
To transform Abe Lincoln to a logarithmic world, just double-click the graph and select the log transform. The result is shown on the right here:<br />
<center><figure style="width: 200px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Transformed Matlab penny image" src="https://undocumentedmatlab.com/images/lincoln_contour.jpg" title="Transformed Matlab penny image" width="200" height="195" /><figcaption class="wp-caption-text">Transformed Matlab penny image</figcaption></figure></center> All plots in Waterloo share a common data model, including contour plots. For a scatter plot, <code>x, y</code> pairs in a set represent the offsets to display a marker e.g. a circle or square that is generally of fixed size. For a contour plot, the marker is the contour line and the values for that incorporate the offsets. The <code>xdata</code> and <code>ydata</code> are added during plotting; while these will normally be zero, this makes it trivial to construct montages of contour plots simply by using non-zero values.<br />
Plainly, this needs some extra work to support the common model: circles for a scatter plot are still painted as fixed diameter circles when the plot is rescaled or transformed but the pixel values for a contour line, bar plot etc will need to be recalculated. To achieve this:</p>
<ul>
<li>the data model incorporates an extra object to do the work</li>
<li>such plots implement a new interface – <code>GJTransformUpdateInterface</code> – that specifies a <i>transformUpdate()</i> method that refreshes the pixel-coordinates. End-users will not normally need to concern themselves with this, as <i>transformUpdate</i> method will be called by the listeners as required.</li>
</ul>
<h3 id="categorical">Categorical data</h3>
<p>Waterloo always uses numeric data to position markers, bars etc in a plot. However, categorical data can be used to supplement those data. Here is an example using the new bar plot:<br />
<center><figure style="width: 320px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Categorized Waterloo bar plot" src="https://undocumentedmatlab.com/images/categorised_bar.png" title="Categorized Waterloo bar plot" width="316" height="183" /> <img loading="lazy" decoding="async" alt="Categorized Waterloo bar plot" src="https://undocumentedmatlab.com/images/categorised_labelled.png" title="Categorized Waterloo bar plot" width="318" height="191" /><figcaption class="wp-caption-text">Categorized Waterloo bar plots</figcaption></figure></center></p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','TestBar4', 'Units','normalized', 'Position',[0.1 0.1 0.8 0.8]);
m = {'Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'};
gr1 = subplot(f, 2, 2, 1);
a = bar(gr1, 1:12, 1:12);
for k = 1 : 12
   a.getObject().getDataModel().getXData().setCategory(k, m{k});
end
gr1.getObject().setTitleText('Label using the XData categories');
gr1.getObject().getView().autoScale();
</pre>
<p>Support for categorical labels on the axes is supported for all plots via the common data model. For bar charts, the extra object associated with the plot also supports adding labels to the bars themselves:</p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','Categorized Bars', 'Units','normalized', 'Position',[0.3 0.3 0.4 0.4]);
m = {'Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'};
gr = subplot(f, 1, 1, 1);
c = barh(gr, 1:10, 1:10,'stacked');
c.getObject().setFill([java.awt.Color.yellow, java.awt.Color.blue]);
c.getObject().getDataModel().getExtraObject().setFontForeground([java.awt.Color.BLACK, java.awt.Color.WHITE]);
for k = 1 : 12
   c.getObject().getDataModel().getExtraObject().getLabels().add(k-1, m{k});
end
gr.getObject().getView().autoScale();
</pre>
<p>Note that the standard method <i>setFill</i>, is used to set the bar colors and as two colors are supplied the data are assumed to contain a pair of multiplexed series. This is common to all plots.<br />
To customize the labels, we need to set a property in the extra object which is retrieved with a call to <i>c.getObject().getDataModel().getExtraObject()</i>.<br />
The same principles apply to pie charts:<br />
<center><figure style="width: 200px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Labelled Waterloo pie chart" src="https://undocumentedmatlab.com/images/pie.png" title="Labelled Waterloo pie chart" width="200" height="204" /><figcaption class="wp-caption-text">Labelled Waterloo pie chart</figcaption></figure></center></p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','TestPie1', 'Units','normalized', 'Position',[0.1 0.1 0.8 0.8]);
colors = [kcl.waterloo.defaults.Colors.getColor(0)];
y = ones(1,18)*100/18;
gr = subplot(f, 1, 1, 1);
colors = [kcl.waterloo.defaults.Colors.getColor(1),...
    kcl.waterloo.defaults.Colors.getColor(17),...
    kcl.waterloo.defaults.Colors.getColor(2),...
    kcl.waterloo.defaults.Colors.getColor(16),...
    kcl.waterloo.defaults.Colors.getColor(3),...
    kcl.waterloo.defaults.Colors.getColor(15),...
    kcl.waterloo.defaults.Colors.getColor(4),...
    kcl.waterloo.defaults.Colors.getColor(14)];
c = pie(gr, [10 20 45 42 22 26 42 20], logical([0 0 1]), 'FaceColor',colors);
</pre>
<h3 id="polar">Polar charts</h3>
<p>Polar bar and compass charts are also now supported:<br />
<center><figure style="width: 500px" class="wp-caption alignright"><a target="_blank" href="/images/polar_bar2.gif"><img loading="lazy" decoding="async" alt="Waterloo polar bar chart (click for details)" src="https://undocumentedmatlab.com/images/polar_bar2.gif" title="Waterloo polar bar chart (click for details)" width="241" height="230" /></a><a target="_blank" href="/images/compass.png"><img loading="lazy" decoding="async" alt="Waterloo compass chart (click for details)" src="https://undocumentedmatlab.com/images/compass.png" title="Waterloo compass chart (click for details)" width="248" height="230" /></a><figcaption class="wp-caption-text">Waterloo polar bar and compass charts (click for details)</figcaption></figure></center></p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','TestPie1', 'Units','normalized', 'Position',[0.1 0.1 0.8 0.8]);
load sunspot.dat  % Contains a 2-column vector named sunspot
colors = [kcl.waterloo.defaults.Colors.getColor(0)];
for k = 1 : 17
    colors = horzcat(colors,kcl.waterloo.defaults.Colors.getColor(k));
end
gr1 = subplot(f, 1,2, 1);
a = polarbar(gr1, sunspot(1:48,2), 'FaceColor',colors, 'EdgeWidth',0.5);
[a,b] = hist(sunspot(:,2),12);
gr2 = subplot(f, 1,2, 2);
b = polarbar(gr2, a, 'FaceColor',colors);
Z = eig(randn(20,20));
a = compass(gr1, real(Z), imag(Z), 'LineColor','r');
</pre>
<h3 id="area">Area plots</h3>
<p>Area plots are supported through a new plot class and also by having all plots implement a new Java interface. To illustrate, create two line plots:<br />
<center><figure style="width: 300px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Waterloo area-fill chart" src="https://undocumentedmatlab.com/images/areaFill1.png" title="Waterloo area-fill chart" width="300" height="141" /><figcaption class="wp-caption-text">Waterloo area-fill chart</figcaption></figure></center></p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','TestAreaFill', 'Units','normalized', 'Position',[0.4 0.1 0.5 0.4]);
x = 0.5 : 0.5 : 10;
y = sin(x);
gr1 = gxgca();
a1 = line(gr1, x, y, 'LineSpec','-ob');
b1 = line(gr1, x, y*2, 'LineSpec','-sg');
gr1.getObject().getView().autoScale();
% Filling the area between the two plots requires one extra line and a refresh call to paint the result:
a1.getObject().setAreaFill(b1.getObject());
refresh();
</pre>
<p>All the work is done in the Java code because plots now implement the <code>GJFillable</code> interface. All that is required is to call the <i>setAreaFill()</i> method on a class implementing <code>GJFillable</code>, specifying another <code>GJFillable</code> as input.<br />
A new java class, <code>GJFill</code>, also implements <code>GJFillable</code> and can be used to fill an area relative to a scalar constant or an arbitrary shape. I have also written a Matlab wrapper class for this (<code>GXFill</code>, see below) but I shall use a Java-based example here.<br />
Whether the fill is made horizontally (from the plot) or vertically (from the axes) can be selected by setting the orientation property of the <code>GJFill</code> instance. This can also be set to arbitrary, in which case we can create a custom fillable area sythesized from <code>java.geom</code> shapes:<br />
<center><figure style="width: 300px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Waterloo full area fill chart" src="https://undocumentedmatlab.com/images/areaFill2.png" title="Waterloo full area fill chart" width="300" height="177" /> <img loading="lazy" decoding="async" alt="Waterloo custom area fill chart" src="https://undocumentedmatlab.com/images/areaFill3b.png" title="Waterloo custom area fill chart" width="300" height="177" /><figcaption class="wp-caption-text">Waterloo full (above) &amp; custom (below) area fill charts</figcaption></figure></center></p>
<pre lang='matlab'>
f = GXFigure();
set(gcf, 'Name','Constant Fill', 'Units','normalized', 'Position',[0.3 0.3 0.4 0.4]);
x = 0.5 : 0.5 : 10;
y = sin(x);
gr1 = subplot(f, 1, 1, 1);
a1 = line(gxgca, x+1, y+3, 'LineSpec','-sg');
% Now create a GJFill instance, using a constant as the reference (1.5 in this case), and use this as this area's fill
v = kcl.waterloo.graphics.plots2D.GJFill(a1.getObject(), 1.5);
a1.getObject().setAreaFill(v);
%% Start complex
   % Alternately, we can use an arbitrary fill shape:
   v.setOrientation(javaMethod('valueOf', 'kcl.waterloo.graphics.plots2D.GJFill$ORIENTATION', 'ARBITRARY'));
   a1.getObject().setAreaFill(v);
   % Create a shape (which can be complex)
   area = java.awt.geom.Area(javaObject('java.awt.geom.Rectangle2D$Double',1,1,5,5));
   area.add(java.awt.geom.Area(javaObject('java.awt.geom.Rectangle2D$Double',8,1,2,5)));
   % Add the shape to the GJFill instance
   v.setArbitraryArea(java.awt.geom.Area(area));
%% End complex
% Customize the fill color
v.setAreaPaint(java.awt.Color(0,1,0,0.5));
% Manually rescale and refresh the plot
gr1.getObject().getView().setAxesBounds(0,0,12,5);
refresh();
</pre>
<p>To make this simpler from Matlab, a new Matlab class <code>GXFill</code> is provided. This constructs and adds a fill in a single step:</p>
<pre lang='matlab'>fill = GXFill(plot_reference, value, orientation);</pre>
<p>where <code>value</code> is a scalar or a Java <code>Shape</code> object, and <code>orientation</code> is a string e.g. &#8216;horizontal&#8217;. Note that the coordinates are specified in axes units and they will rescale and be transformed as needed when the axes are changed.</p>
<h3 id="ROI">Specifying/selecting ROIs</h3>
<p>Finally, regions of interest (ROIs) can be selected both programmatically and with the mouse. One of these can be set as the &#8220;current&#8221; ROI and that is the one that is mouse selectable: set the current ROI using shift-left mouse drag, set the region and rescale to display only that region using shift-right mouse drag.<br />
To create an ROI that can be dragged and resized, add a <code>GJRoi</code> instance to the graph, e.g. with an existing current ROI selected:</p>
<pre lang='matlab'>
gr = gxgca;
gr = gr.getObject().getView();
gr.add(kcl.waterloo.graphics.GJRoi.createInstance(gr, gr.getCurrentROI()));
</pre>
<h3 id="java">Waterloo and Matlab&#8217;s Java support</h3>
<p>Note: It appears that HG2, like HG1, creates an offscreen bitmap that is then blitted onto a Java <code>Canvas</code> within a Matlab figure. Matlab <a target="_blank" rel="nofollow" href="https://www.mathworks.com/support/contact_us/dev/javaframe.html">warns</a> that the JavaFrame property will (no longer may) be discontinued in some future release, but it is my guess that this will not be the case when HG2 is released. A new set of uicontrols may indeed be included using a C-based library like <a target="_blank" rel="nofollow" href="http://www.wxwidgets.org">wxWidgets</a> or <a target="_blank" rel="nofollow" href="https://qt-project.org">Qt</a>. However, it seems unlikely that Java support will be dropped completely – too much of Matlab&#8217;s GUI uses Java (for example, the new desktop introduced in R2012b is entirely Java-based). So the Waterloo Matlab library should work, even if a switch is needed to using <code>JFrame</code>s instead of Matlab figures for output.<br />
For the adventurous, Waterloo graphs can also be deployed using <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/JavaFX">JavaFX</a> via the <a target="_blank" rel="nofollow" href="http://download.java.net/jdk8/jfxdocs/javafx/embed/swing/SwingNode.html">SwingNode</a> class – but that requires installation of the latest <a target="_blank" rel="nofollow" href="https://jdk8.java.net/download.html">Java 8</a> (currently in early release status). Noting that Matlab is still (as of R2013a) using Java 6, this may indeed be a big jump (note last week&#8217;s article on <a target="_blank" href="/articles/using-java-7-in-matlab-r2013a-and-earlier/">upgrading Matlab to use Java 7</a>).<br />
Naturally, Waterloo&#8217;s graphs and classes can also be used in stand-alone Java applications, entirely outside Matlab, even on a $30 ARM6 <a target="_blank" rel="nofollow" href="http://www.raspberrypi.org">Raspberry Pi</a>.<br />
Next week, I will look at methods for animating plots (e.g. using Matlab timers) and deploying vector graphics to web pages using the in-built GUIs.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/waterloo-graphics-beta">Waterloo graphics beta</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics-examples" rel="bookmark" title="Waterloo graphics examples">Waterloo graphics examples </a> <small>Some Matlab usage examples for the open-source Waterloo graphics package. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics-animation-web-deployment" rel="bookmark" title="Waterloo graphics animation and web deployment">Waterloo graphics animation and web deployment </a> <small>Waterloo graphics can be updated very quickly in Matlab, enabling plot animation; web deployment of the graphics is also possible. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/waterloo-graphics" rel="bookmark" title="Waterloo graphics">Waterloo graphics </a> <small>Waterloo is an open-source library that can significantly improve Matlab GUI. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-hg2-graphics-events" rel="bookmark" title="Undocumented HG2 graphics events">Undocumented HG2 graphics events </a> <small>Matlab's new HG2 graphics engine includes many new undocumented events that could be used in various ways. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/waterloo-graphics-beta/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>HG2 update</title>
		<link>https://undocumentedmatlab.com/articles/hg2-update?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hg2-update</link>
					<comments>https://undocumentedmatlab.com/articles/hg2-update#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 16 May 2013 00:38:19 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3789</guid>

					<description><![CDATA[<p>HG2 appears to be nearing release. It is now a stable mature system. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hg2-update">HG2 update</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-rulers" rel="bookmark" title="Customizing axes rulers">Customizing axes rulers </a> <small>HG2 axes can be customized in numerous useful ways. This article explains how to customize the rulers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-2" rel="bookmark" title="Customizing axes part 2">Customizing axes part 2 </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Exactly three years ago, I posted information (<a target="_blank" href="/articles/matlab-hg2/">here</a> and <a target="_blank" href="/articles/new-information-on-hg2/">here</a>) about Matlab&#8217;s upcoming new graphics engine, so-called HG2 (<i>Handle Graphics version 2</i>). At the time, I was sure that HG2 was just around the corner. But three years and six releases have passed, Matlab 7 turned into Matlab 8, and HG1 is still in use. I decided that it was time to revisit the latest state of HG2, as reflected in the latest release, R2013a (Matlab 8.1).<br />
In the past few years, development of HG2 has apparently progressed to a stage where most of the kinks were ironed out. The latest HG2 appears to be quite stable, and in my experience most GUI/graphics utilities run as-is, without any need for tweaking. This is good news, which leads me to think that HG2 will be released soon. It is possible that this could happen as early as the upcoming release (R2013b, 8.2) but I have a gut feeling that it will be in R2014a. I also have a gut feeling that MathWorks will name that release 9.0 rather than 8.3, in keeping with its arch-rival <a target="_blank" rel="nofollow" href="http://www.wolfram.com/mathematica/">Mathematica</a>.<br />
HG2 has improved grid lines, plot anti-aliasing and customizable everything (more on this below). Here&#8217;s a simple plot line as it appears in both HG1 and HG2:</p>
<pre lang='matlab'>
hFig = figure('pos',[100,100,300,250]);
x = -10:0.1:10;
y = 1e7*sin(x)./x;
hLine = plot(x,y);
box off; grid on;
title('HG2 plot');
</pre>
<p><center><figure style="width: 620px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="HG1 plot" src="https://undocumentedmatlab.com/images/HG1_plot.png" title="HG1 plot" width="300" height="325" /><img loading="lazy" decoding="async" alt="HG2 plot" src="https://undocumentedmatlab.com/images/HG2_plot.png" title="HG2 plot" width="300" height="325" /><figcaption class="wp-caption-text">Same plot in HG1 and HG2</figcaption></figure></center><br />
We can see that MathWorks has invested heavily in improving usability. The graphics are now much more visually appealing than before. A lot of thought has gone into small details such as the plot colors and the axes gray shades. The changes are small when taken separately, but the overall gestalt is striking. HG2 will definitely justify my license maintenance cost.<br />
<b><u>Addendum Oct 3 2014</u></b>: HG2 is finally released in Matlab release R2014b (8.4 &#8211; not 9.0 as I surmised above). However, many of the advanced customizations shown in this article are still unsupported and undocumented. I plan to detail them in a separate upcoming series of articles.<br />
<span id="more-3789"></span></p>
<h3 id="customizable">Highly customizable</h3>
<p>Matlab in HG2 mode acts and behaves pretty much as you would expect. There are no visible changes to the Desktop or the graphics interface. The major difference is that all graphics handles, whether interactive controls (figure, uicontrols, uitables, etc.) or graph elements (axes, lines, patches, etc.) are instances of class objects (e.g., <code>matlab.ui.Figure</code> or <code>matlab.graphics.chart.primitive.Line</code>) rather than numeric values. This makes it easy to issue commands such as:</p>
<pre lang='matlab'>
hFig.Color = 'w';
hAxes = gca;
hAxes.Title.Color = 'm';  % default: [0,0,0] = black
hAxes.YRuler.SecondaryLabel.String = 'millions';  % original: 'x10^{6}'
hAxes.YRuler.SecondaryLabel.FontAngle = 'italic';  % default: 'normal'
hAxes.YRuler.Axle.LineStyle = 'dotted';  % default: 'solid'
hAxes.YRuler.Axle.ColorData = uint8([0,100,0,255])';  %=dark green; default: [51 51 51 255], corresponding to [0.2 0.2 0.2 1]
hAxes.YBaseline.Color = 'b';  % default: [0.2 0.2 0.2]
hAxes.YBaseline.Visible = 'on';  % default: 'off'
hAxes.XRuler.Axle.Visible = 'off';  % default: 'on'
hLine.Color = [1,0,0];  %='red'
</pre>
<p>rather than using the corresponding <i><b>set(&#8230;)</b></i> or <i><b>get(&#8230;)</b></i> functions, which are still supported for backward compatibility.<br />
<center><figure style="width: 316px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Customized HG2 plot" src="https://undocumentedmatlab.com/images/HG2_plot2.png" title="Customized HG2 plot" width="316" height="342" /><figcaption class="wp-caption-text">Customized HG2 plot</figcaption></figure></center><br />
Notice how much more customizable HG2 is compared to HG1. I am pretty excited from the huge number of additional possible customizations in HG2 compared to HG1. It is real a pity that many of these customizations rely on hidden/undocumented properties (see below). Hopefully this will change when HG2 is officially released.</p>
<h3 id="observations">Some observations</h3>
<p>Here are a few observations that I collected on the latest HG2, as reflected in R2013a:</p>
<ol>
<li>Java is still supported (hurray!). The warnings about the figure&#8217;s <a target="_blank" href="/articles/disable-entire-figure-window/#JavaFrame"><b>JavaFrame</b> property</a> becoming deprecated have fortunately not been fulfilled (hopefully never). All the Java-based GUI tricks shown on this blog and in my book still work, excluding some minor things here and there which are due to inter-release changes rather than to the new HG2 engine.</li>
<li>In order to access the top-level Java <code>Frame</code> of a figure window, we now need to use <code>javaFrame.fHG2Client</code> rather than <a target="_blank" href="/articles/docking-figures-in-compiled-applications/"><code>javaFrame.fHG1Client</code></a>. The relevant code should now look something like this, in order to be fully-compatible with older Matlab releases:
<pre lang='matlab'>
jFrame = get(handle(hFig), 'JavaFrame');
try
    % This works up to R2011a
    jFrame.fFigureClient.setClientDockable(true);
catch
    try
        % This works from R2008b and up, up to HG2
        jFrame.fHG1Client.setClientDockable(true);
    catch
        % This works in HG2
        jFrame.fHG2Client.setClientDockable(true);
    end
end
</pre>
</li>
<li>Anti-aliasing of plot elements (a.k.a. line -smoothing) is now &#8216;on&#8217; by default (double hurray!). Apparently, MathWorks solved the problems with the existing <a target="_blank" href="/articles/plot-linesmoothing-property/">undocumented <b>LineSmoothing</b> property</a>. Still, for some unknown reason, <b>LineSmoothing</b> remains a hidden/undocumented property. Note that for some objects the property name is different. For example, the axes title (which is a <i><b>text</b></i> object of class <code>matlab.graphics.primitive.Text</code>) has a new property called <b>Smoothing</b> that controls anti-aliasing (unlike <b>LineSmoothing</b>, <b>Smoothing</b> appears to be an un-hidden fully-documented property).<br />
<b><u>R2013b addendum</u></b>: The figure handle now includes a property called <b>GraphicsSmoothing</b> that controls anti-aliasing at the entire figure level (default=&#8217;on&#8217;). No more need to set individual graphic elements, although we still can if we want (alas, this flexibility may be removed soon &#8211; see item #6 below). I would have liked to see the anti-aliasing feature use the same property name for all graphic elements, rather than <b>GraphicsSmoothing/LineSmoothing/Smoothing</b>, but maybe I&#8217;m just being an ungrateful spoil-sport&#8230; The good news about <b>GraphicsSmoothing</b> is that this is a <u>non-hidden</u> property. This means it can be seen with <i><b>get</b>(gcf)</i> and once HG2 becomes live it will become fully documented/supported &#8211; hurray!
</li>
<li>Many new properties have been added to graphic objects, that enable customization of different aspects. For example, we can customize the axes grid-lines, containing box and exponent labels in ways that were impossible in HG1 (triple hurray!). Note that many of these new properties are hidden/undocumented (why the hell for???), so we need a utility such as my <a target="_blank" href="/articles/uiinspect/"><i><b>uiinspect</b></i></a> or <a target="_blank" rel="nofollow" href="/articles/getundoc-get-undocumented-object-properties/"><i><b>getundoc</b></i></a> to detect them. Some of the useful new axes properties include <b>*Ruler, *Baseline, *GridHandle, BoxFrame</b> and <b>BackDrop</b> (I showed an example usage of <b>*Ruler</b> and <b>*Baseline</b> above). I have absolutely no idea why these so-useful properties are kept hidden, it simply makes no sense.</li>
<li>Some existing HG1 properties are missing. For example, the <b>UserData</b> property is no longer available for some Java objects (this is a real pity &#8212; I depended on it for many functionalities, such as storing node-specific data in <i><b>uitree</b></i>/<code>JTree</code> nodes). Similarly, axes no longer have <a target="_blank" href="/articles/plot-liminclude-properties/"><b>*LimInclude</b> properties</a> (this actually makes sense &#8211; these properties are still available in plot lines, where they actually have a use).</li>
<li>Some existing HG1 properties now issue a warning, although they still work. For example:
<pre lang='matlab'>
>> hAxes.DrawMode = 'fast';
Warning: The DrawMode property will be removed in a future release.
(Type "warning off MATLAB:hg:willberemoved" to suppress this warning.)
>> hLine.LineSmoothing
Warning: The LineSmoothing property will be removed in a future release.
(Type "warning off MATLAB:hg:willberemoved" to suppress this warning.)
ans =
on
</pre>
<p><b><u>R2013b addendum</u></b>: <code>hAxes.DrawMode</code> no longer issues a warning, although <code>hLine.LineSmoothing</code> does.
</li>
<li>There is an open bug on R2012b and R2013a whereby the <i><b>clf</b></i> function does not delete <a target="_blank" href="/articles/javacomponent/"><i><b>javacomponent</b></i></a> objects. This bug does not affect HG2, where <i><b>clf</b></i> works properly.</li>
<li>Some GUI components are being placed a pixel or two sideways in HG2 compared to HG1. This has no visual importance except in very rare cases, but it does affect my <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a>, which relies on the component&#8217;s position to find its underlying Java object. I have updated <i><b>findjobj</b></i> for the upcoming HG2 and it should work with both HG1 and HG2.</li>
<li>The default axes and labels color has changed from black to gray ([0.2 0.2 0.2]). Grid lines now use an even lighter gray shade. Visually I think that this is a great change, since it directs the viewer&#8217;s focus on the plot contents rather than the external decorations.
	</li>
<li>The default axes plot color order has changed. The standard plot color is no longer blue (as it was for ages in Matlab), but a bluish tint; the second color is no longer red but light green; the third color is reddish rather than dark green, etc.:
<pre lang='matlab'>
% HG1
>> get(0,'defaultAxesColorOrder')
ans =
            0            0            1
            0          0.5            0
            1            0            0
            0         0.75         0.75
         0.75            0         0.75
         0.75         0.75            0
         0.25         0.25         0.25
%HG2
>> get(0,'defaultAxesColorOrder')
ans =
     0.070588      0.40784      0.70196
      0.92941      0.14118      0.14902
      0.60784       0.7451      0.23922
      0.48235      0.17647       0.4549
            1      0.78039            0
      0.30196       0.7451      0.93333
      0.82353       0.4549            0
</pre>
<p><b><u>R2013b addendum</u></b>: The default colors have changed a bit (for the better I think). I still think that the relative order should more closely match the current order (blue-green-red-etc.), for compatibility with existing apps. A small utility function could be added that modifies the color-order to something that may be better suited for color-differentiation (see Tim Holy&#8217;s excellent <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors">utility</a> for an example).
</li>
<li>HG2 axes no longer forget the previous plot color (unless we used <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/loren/2009/06/03/hold-everything/"><i><b>hold all</b></i></a>) &#8212; in HG2 color cycling is on by default. Note that this causes some visual discrepancies between HG1 and HG2 in plots that use <i><b>hold on</b></i> and have multiple plot lines: In HG1 they were all blue; in HG2 the first is bluish, the second is greenish, then reddish etc.</li>
<li>GUIDE is still the same-ol&#8217; GUIDE (sigh!). The figure toolbar and menubar have likewise not been upgraded, as far as I could tell.</li>
<li>HG2 performance appears to be generally slower than HG1. Hopefully this will improve by the time HG2 is released, since performance has been one of HG1&#8217;s drawbacks all along. In my tests, most GUI/graphic aspects ran only slightly slower in HG2, except for 2D plots that were significantly slower. This is corroborated by running <i><b>bench</b></i>: on my computer, HG1 yields 0.4 for 2D and 0.22 for 3D; in HG2 the performance is 2.1 for 2D and 0.18 for 3D. Looks like the 2D performance still needs some work&#8230;</li>
</ol>
<h3 id="testing">Testing HG2</h3>
<p>As noted in my <a target="_blank" href="/articles/matlab-hg2/">original article</a>, we can start Matlab in HG2 mode by simply adding the startup (command-line) switch <i>-hgVersion 2</i> to the Matlab command (note the space between the <code>-hgVersion</code> and the &#8220;2&#8221;). For example, in Windows, all you need to do is to copy your Matlab shortcut sideways (so that you will always have the standard HG1 version available), then right-click the shortcut, select &#8220;Properties&#8221;, then add <i>-hgVersion 2</i> to the Target field (note the space between &#8220;hgVersion&#8221; and &#8220;2&#8221;). You will probably want to also add the &#8220;HG2&#8221; descriptor to the shortcut name, in the &#8220;General&#8221; tab:<br />
<center><figure style="width: 377px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab startup switch for HG2" src="https://undocumentedmatlab.com/images/HG2_shortcut_props.png" title="Matlab startup switch for HG2" width="377" height="428" /><figcaption class="wp-caption-text">Matlab startup switch for HG2</figcaption></figure></center><br />
If you have any Matlab application that relies on GUI or graphics, I urge you to test it on the new HG2 system. It&#8217;s trivially simple and your application should work exactly the same, or better. If you do detect some incompatibility, please <a href="/articles/hg2-update/#respond">post a comment</a> or <a href="mailto: altmany @gmail.com?subject=HG2 feedback&amp;body=Hi Yair, &amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=HG2 feedback&amp;body=Hi Yair, '); return false;">shoot me an email</a>. In due course I expect that MathWorks will open an official channel for this, but in the meantime I&#8217;ll be sure to pass the information to the relevant person.<br />
Do take a moment for testing HG2 &#8211; we can all contribute to ensure that when HG2 does come out it will be perfect. It&#8217;s in our interest.</p>
<h3 id="NYC_visit">NYC visit</h3>
<p>If you happen to be in New York next week, I urge you to attend the MATLAB Computational Conference on Thursday May 23 (free <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/registration.html">registration</a>; my presentation is scheduled for 4:50pm). I would be happy to meet you to discuss how I could bring value to your needs, either financial-oriented or not. We could meet at the conference, or anywhere in New York on Wednesday May 22 or Friday May 24.<br />
<center><a href="/articles/nyc-visit-may-2013/"><img loading="lazy" decoding="async" title="Matlab Computational Finance Conference - 23 May 2013" src="https://undocumentedmatlab.com/images/conference_invite_animated.gif" alt="Matlab Computational Finance Conference - 23 May 2013" width="324" height="86"/></a></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hg2-update">HG2 update</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-rulers" rel="bookmark" title="Customizing axes rulers">Customizing axes rulers </a> <small>HG2 axes can be customized in numerous useful ways. This article explains how to customize the rulers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-2" rel="bookmark" title="Customizing axes part 2">Customizing axes part 2 </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/hg2-update/feed</wfw:commentRss>
			<slash:comments>134</slash:comments>
		
		
			</item>
		<item>
		<title>JTattoo look-and-feel demo</title>
		<link>https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jtattoo-look-and-feel-demo</link>
					<comments>https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 20 Mar 2013 16:00:11 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Karthik Ponudurai]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3687</guid>

					<description><![CDATA[<p>A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo">JTattoo look-and-feel demo</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/modifying-matlab-look-and-feel" rel="bookmark" title="Modifying Matlab&#039;s Look-and-Feel">Modifying Matlab&#039;s Look-and-Feel </a> <small>Matlab's entire Look-and-Feel (PLAF, or L&F) can be modified at the control or application level - this article shows how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo" rel="bookmark" title="Real-time trading system demo">Real-time trading system demo </a> <small>A real-time Matlab-based end-to-end trading system demo is presented ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps" rel="bookmark" title="Using pure Java GUI in deployed Matlab apps">Using pure Java GUI in deployed Matlab apps </a> <small>Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Three years ago, I wrote an article about modifying <a target="_blank" href="/articles/modifying-matlab-look-and-feel/">Matlab&#8217;s look-and-feel</a> (L&#038;F, or LnF), using Java&#8217;s built-in support for replaceable LnFs. To date, that article has 27 comments by 13 different commenters (plus 20 responses by me), making it the second most active article on this website. I decided to follow up on that article with a demo that shows the effects that different L&#038;Fs have on GUI controls, and a demonstration of the JTattoo library of professional L&#038;Fs.<br />
Today&#8217;s article and the demo are based on original work by <a target="_blank" href="/articles/tag/karthik-ponudurai/">Karthik Ponudurai</a>, who has written a guest article here about an interesting <a target="_blank" href="/articles/matlab-java-interface-using-static-control/">technique to interface a Java GUI to a Matlab application</a>, a couple of years ago.<br />
<center><figure style="width: 500px" class="wp-caption aligncenter"><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/40866-jtattoo-look-and-feel-demo-gui"><img loading="lazy" decoding="async" alt="Demo of using different Look-and-Feels in Matlab GUI" src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/40866/versions/2/screenshot.gif" title="Demo of using different Look-and-Feels in Matlab GUI" width="500" height="421" /></a><figcaption class="wp-caption-text">Demo of using different Look-and-Feels in Matlab GUI</figcaption></figure></center><br />
<!-- My local image version: https://undocumentedmatlab.com/images/JTattooDemo_animated.gif --><br />
<span id="more-3687"></span><br />
<a target="_blank" rel="nofollow" href="http://www.jtattoo.net/">JTattoo</a> is a 3rd-party open-source library. The purpose of including it in the demo, in addition to its natural use as a professional set of L&#038;Fs, is to demonstrate how easy it is to integrate 3rd-party L&#038;Fs in Matlab. In the demo I use the current latest <a target="_blank" rel="nofollow" href="http://www.jtattoo.net/Download.html">available</a> JTattoo library (1.6.7), but you can always download the latest version and replace the <i>JTattoo.jar</i> file. JTattoo contains a large set of different L&#038;Fs that can be used independently (<a target="_blank" rel="nofollow" href="http://www.jtattoo.net/ScreenShots.html">screenshots</a>). The nice thing about L&#038;Fs is that since all Matlab GUI is based on Java Swing, the new L&#038;Fs automatically affect Matlab controls just like native Java ones.<br />
The demo can be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/40866-jtattoo-look-and-feel-demo-gui">downloaded</a> from the Matlab File Exchange. After downloading, unzip it into any folder on your Matlab path and run <i>JTattooDemo.m</i>.<br />
A Matlab figure is displayed with two panels, one containing Matlab uicontrols (within a simple <a target="_blank" href="/articles/matlab-layout-managers-uicontainer-and-relatives/"><i><b>uiflowcontainer</b></i></a>) and the other containing Java components.<br />
Two main menus are available: <i>System</i> enables selecting the standard Swing L&#038;Fs that are installed on your system (this varies a bit between platforms and Matlab releases); <i>JTattoo</i> enables selecting one of the JTattoo L&#038;Fs. Once the user selects any of the L&#038;F menu items, the entire figure is updated. This is done by calling <code>javax.swing.SwingUtilities.updateComponentTreeUI()</code> on the figure&#8217;s <a target="_blank" href="/articles/minimize-maximize-figure-window/#JavaFrame">Java Frame</a>&#8216;s content pane. Both the Matlab and the Java controls within the figure are automatically updated by this Swing function to reflect the newly-selected L&#038;F. Care is taken to update the L&#038;F on the <a target="_blank" href="/articles/matlab-and-the-event-dispatch-thread-edt/">EDT</a>, to prevent racing-condition issues.<br />
It should be noted that the demo resets the L&#038;F after updating the figure, otherwise any new figure or window would open using the newly-selected L&#038;F. This is done in the <i>updateInterface</i> function as follows:</p>
<pre lang='matlab'>
function updateInterface( lookandfeel )
    % Preserve the original L&F, before updating
    originalLnF = javax.swing.UIManager.getLookAndFeel;
    % Update the L&F in the demo figure as requested
    ... (all the existing code within the function)
    % Restore the original L&F for any new figure/window
    javax.swing.UIManager.setLookAndFeel(originalLnF);
end  % updateInterface
</pre>
<p>Note that after changing the L&#038;Fs several times, some L&#038;F properties night get &#8220;mixed-up&#8221; causing odd-looking L&#038;Fs. The simplest solution in this case is to restart Matlab&#8230;<br />
<center><figure style="width: 350px" class="wp-caption alignright"><a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze"><img loading="lazy" decoding="async" alt="Matlab open training day (Israel) - click for details" src="https://undocumentedmatlab.com/courses/Matlab_open_day_350x225b.png" title="Matlab open training day (Israel) - click for details" width="350" height="225"/></a><figcaption class="wp-caption-text">Matlab open training day (Israel) - click for details</figcaption></figure></center><br />
Readers in Israel are invited to attend a free training seminar that I will present on advanced Matlab topics in Herzliya, on Thursday April 4, 2013. The seminar is free, but requires registration. <a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze">Additional details here</a>. I will speak in Hebrew, but the presentation will be in English and I will be happy to answer questions in English.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo">JTattoo look-and-feel demo</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/modifying-matlab-look-and-feel" rel="bookmark" title="Modifying Matlab&#039;s Look-and-Feel">Modifying Matlab&#039;s Look-and-Feel </a> <small>Matlab's entire Look-and-Feel (PLAF, or L&F) can be modified at the control or application level - this article shows how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo" rel="bookmark" title="Real-time trading system demo">Real-time trading system demo </a> <small>A real-time Matlab-based end-to-end trading system demo is presented ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps" rel="bookmark" title="Using pure Java GUI in deployed Matlab apps">Using pure Java GUI in deployed Matlab apps </a> <small>Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Disabling menu entries in deployed docked figures</title>
		<link>https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=disabling-menu-entries-in-deployed-docked-figures</link>
					<comments>https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 14 Nov 2012 18:00:46 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Listeners]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Alexander Mering]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Docking]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Listener]]></category>
		<category><![CDATA[Menubar]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3344</guid>

					<description><![CDATA[<p>Matlab's standard menu items can and should be removed from deployed  docked figures. This article explains how. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures">Disabling menu entries in deployed docked figures</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/docking-figures-in-compiled-applications" rel="bookmark" title="Docking figures in compiled applications">Docking figures in compiled applications </a> <small>Figures in compiled applications cannot officially be docked since R2008a, but this can be done using a simple undocumented trick....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps" rel="bookmark" title="Using pure Java GUI in deployed Matlab apps">Using pure Java GUI in deployed Matlab apps </a> <small>Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-9-popup-figures" rel="bookmark" title="Matlab toolstrip – part 9 (popup figures)">Matlab toolstrip – part 9 (popup figures) </a> <small>Custom popup figures can be attached to Matlab GUI toolstrip controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures" rel="bookmark" title="JGraph in Matlab figures">JGraph in Matlab figures </a> <small>JGraph is a powerful open-source Java library that can easily be integrated in Matlab figures. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Last week I presented an <a target="_blank" href="/articles/removing-user-preferences-from-deployed-apps/">article</a> explaining how to solve an issue with deployed (compiled) Matlab applications. Today I&#8217;d like to welcome guest blogger <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/208302">Alexander Mering</a>, who will explain how to disable standard Matlab menu items in deployed docked Matlab figures. Alexander has been an avid follower of this blog, and from his <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/search_results?dur=all&#038;search_string=authorid%3A146471">CSSM posts</a> we can tell that he&#8217;s been heavily using advanced GUI features presented in this blog. His article today nicely shows how we can use different building-blocks presented in different articles in this blog, to achieve something new and useful.</i><br />
As Yair pointed out in many occasions, the power of Matlab could be greatly enhanced using the underlying Java mechanism. To me, while developing a larger standalone tool for technical calculations, these hints are worth a mint (as I guess for many of you).<br />
One of these very useful hints is the ability to <a target="_blank" href="/articles/docking-figures-in-compiled-applications/">dock figure windows in standalone applications</a>. This perfectly fits to my understanding of a &#8220;clean desktop&#8221;, i.e., having as less as possible separate windows. Since in many calculations dozens of figures are generated, the desktop gets up crowded very fast &#8211; if these are not grouped. So docking is essential (at least for me). Unfortunately there seems to be a serious problem with the resulting menu entries (at least in R2011b on Win XP), leading to a crash of the standalone application. Based on the posts by Yair, I will sketch a possible route to avoid this issue.</p>
<h3 id="symptom">The symptom</h3>
<p>In the compiled application, docking could be accomplished by accessing the figure frame&#8217;s underlying Java level:</p>
<pre lang='matlab'>
% get java frame for sophisticated modifications
jframe = get(handle(figure_handle), 'JavaFrame');
% allow docking
jframe.fHG1Client.setClientDockable(true)
</pre>
<p>Using this modification, the user is now allowed to dock and undock the figures manually. For initial docking of the figure,</p>
<pre lang='matlab'>javaFrame.fHG1Client.setClientWindowStyle(true,false)</pre>
<p>could be used during figure creation. Unfortunately, there are menu entries in the Figures container which are either unwanted (since not usable) or even directly crash the standalone applications:<br />
<span id="more-3344"></span><br />
<center><figure style="width: 320px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Useless Debug menu items in deployed applications" src="https://undocumentedmatlab.com/images/Useless_debug_menu.png" title="Useless Debug menu items in deployed applications" width="320" height="267" /><figcaption class="wp-caption-text">Useless Debug menu items in deployed applications</figcaption></figure></center><br />
<center><figure style="width: 504px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Menu items crashing deployed applications" src="https://undocumentedmatlab.com/images/Buggy_desktop_menu.png" title="Menu items crashing deployed applications" width="504" height="241" /><figcaption class="wp-caption-text">Menu items crashing deployed applications</figcaption></figure></center><br />
Since crashing menu entries will be found and used by end-users (though these are somehow hidden), these prohibit the usage of the docking feature as long as these could be invoked. So how can we disable / remove these menu items?</p>
<h3 id="unsuccessful">The unsuccessful solution</h3>
<p>Unfortunately, the straight forward solution of getting the handle to the Figures containers&#8217; menu bar and remove the unwanted items does not work. The reason for this is the (to me unexpected behavior) that the menu bar seems to be rebuilt whenever a figure is docked/undocked.<br />
This is actually the same behavior that automatically rebuilds the Editor&#8217;s menu bar whenever an editor file is added/removed. The Editor container is basically the same docking container as the Figures container, as shown by Yair&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/16650-setfigdockgroup"><i><b>setFigDockGroup</b></i> utility</a>:<br />
<center><figure style="width: 504px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Docking a figure in the Editor container (group)" src="https://undocumentedmatlab.com/images/setFigDockGroup.png" title="Docking a figure in the Editor container (group)" width="504" height="551" /><figcaption class="wp-caption-text">Docking a figure in the Editor container (group)</figcaption></figure></center><br />
Therefore, removing unwanted menu items only helps until the next figure docking/undocking. To make it even worse: also pressing any of the buttons within the document bar (if having more than one figure) somehow rebuilds the entire menu structure, reverting our changes. So the solution becomes a bit more complex.</p>
<h3 id="solution">The working solution</h3>
<p>For the working solution, many pieces presented by Yair should be put together. The first piece results from the question how to detect a dock/undock event. Since no such callback is defined, we need to use a property listener as Yair showed in his post about the <a target="_blank" href="/articles/continuous-slider-callback/">continuous slider callback</a>:</p>
<pre lang='matlab'>
% listen to the WindowStyle property to detect docking / undocking events
hProp = findprop(handle(figure_handle),'WindowStyle');  % a schema.prop object
% if the event occurs, invoke the callback
hlistener = handle.listener(handle(figure_handle), hProp, 'PropertyPostSet',{@(source, event) Callback_DockingFcn});
% attach listener to the GUI since it needs to be known (as long as the figure exists)
setappdata(figure_handle, 'Handle_Listener', hlistener);
</pre>
<p>Now, whenever the figure&#8217;s <b>WindowStyle</b> property (which controls the docking state) is changed, our docking callback is invoked.<br />
The next piece of the puzzle takes care of the menu rebuild whenever any document bar button is pressed. To overcome this behavior, the idea is to define the <b>MousePressed</b> callback of theses buttons to (again) invoke the docking callback. This is necessary for two reasons: First, pressing the button (i.e., changing the current figure) rebuilds the menu, overwriting our changed menu entries. Secondly, all other buttons are also somehow rebuilt and the callbacks are removed if a new figure is docked.<br />
The handles to the document bar buttons could be found using Yair&#8217;s <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a>. We have already seen that the Editor container is analogous to the Figures docking container. So let&#8217;s use the method described by Yair for <a target="_blank" href="/articles/accessing-the-matlab-editor/">accessing the Editor container</a>, to access the Figures container:</p>
<pre lang='matlab'>
figures_container = javaObjectEDT(matlab_instance.getGroupContainer('Figures'));
figures_frame = javaObjectEDT(figures_container.getTopLevelAncestor);
</pre>
<p>Once we get the Java Frame for the Figures container, the buttons could be found by digging through its children. This finally allows to set the callback using</p>
<pre lang='matlab'>
DTDocumentBar = javaObjectEDT(figures_frame.getRootPane.getLayeredPane.getComponent(1).getComponent(1).getComponent(0).getComponent(0).getComponent(1).getComponent(0));
ContentPanel = javaObjectEDT(DTDocumentBar.getComponent(0).getComponent(0).getViewport.getView);
if ~isempty(ContentPanel.getComponents) % less than two documents are open and no DTDocumentbar exists
    drawnow; pause(0.05)
    GroupPanel = javaObjectEDT(ContentPanel.getComponent(0));
    GroupPanel_Elements = javaObjectEDT(GroupPanel.getComponents);
    % change the MousePressed Callback for each of the buttons to invoke the function which disables the menu
    for n = 1 : GroupPanel.getComponentCount
        thisElement = GroupPanel_Elements(n);
        if isequal(char(thisElement.getClass.toString), 'class com.mathworks.widgets.desk.DTDocumentBar$DocumentButton')
            set(handle(thisElement, 'CallbackProperties'), 'MousePressedCallback', {@(source, event) Cbrake_Callback_Diagrams_DockingFcn})
        end
    end
    drawnow; pause(0.05)
end
</pre>
<p>where the loop runs through the current buttons in the document bar.<br />
As the last step of our procedure, we finally remove (or disable) the menu entries which are unwanted. This is achieved by extracting the handle to the Figures menu by:</p>
<pre lang='matlab'>figures_menu = javaObjectEDT(figures_frame.getJMenuBar);</pre>
<p>Running through the menu items, searching for the unwanted entries (as long as they have pre-defined <a target="_blank" href="/articles/modifying-default-toolbar-menubar-actions/">menu-item names</a>) at the end sets us into the position to take care of the menu items:</p>
<pre lang='matlab'>
% run through top-level menu items
for n = 1 : figures_menu.getMenuCount
    % completely deactivate Debugging options
    if isequal(char(figures_menu.getMenu(n-1).getName), 'DesktopDebugMenu')
        DesktopDebugMenuPos = n - 1;
    end
    % Remove some items from the Desktop menu
    if isequal(char(figures_menu.getMenu(n-1).getName), 'DesktopMenu')
        desktop_menu = javaObjectEDT(figures_menu.getMenu(n-1));
        DeletePos = [];
        for m = 1: desktop_menu.getMenuComponentCount
            if ismember({char(desktop_menu.getMenuComponent(m-1).getName)}, ...
                        {'ToggleFigure PaletteCheckBoxMenuItem', 'TogglePlot BrowserCheckBoxMenuItem', 'ToggleProperty EditorCheckBoxMenuItem'})
                DeletePos(end+1) = m - 1;
            end
        end
        for m = length(DeletePos) : -1 : 1
            desktop_menu.remove(DeletePos(m))
        end
    end
end
% finally remove the "Debug" menu
if ~isempty(DesktopDebugMenuPos)
    figures_menu.remove(DesktopDebugMenuPos)
end
</pre>
<p>Since this callback is invoked whenever a figure is docked/undocked, or the currently shown figure is changed (by pressing the document bar button), all unwanted menu items within the Figures menu could be removed.<br />
As a result, the new Figures container menu looks like:<br />
<center><figure style="width: 319px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Deployed menu without unwanted items" src="https://undocumentedmatlab.com/images/Reduced_figures_menu.png" title="Deployed menu without unwanted items" width="319" height="205" /><figcaption class="wp-caption-text">Deployed menu without unwanted items</figcaption></figure></center></p>
<h3 id="remarks">Remarks</h3>
<p>I must admit that above solution is still imperfect. For instance, sometimes there is a larger delay between the docking (or button press event) and the removing of the menu item. Nevertheless, this solution allows me to distribute my standalone with docked figures without having menu items directly leading to a fatal error.<br />
Obviously, the solution has some positive side effects:</p>
<ul>
<li>As could be seen from the screen shot, the Matlab desktop becomes available also within your compiled applications. This might be wanted. If not, it could be removed the same way as the other menu items. One drawback of making the desktop available should be mentioned: In my tests, the standalone Matlab desktop shows the whole list of recent files I have in the Matlab editor at compile time. This is somehow ugly but not that problematic.</li>
<li>Additional menu items could be added, giving more possibilities for modifications.</li>
</ul>
<p>I have uploaded a first version of the docking and creation functions, together with a small test project, to the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/39026-figures-menu-adaption-for-standalone-applications">Matlab file Exchange</a>. Readers are welcome to download the code and send me improvement suggestions. Or you could simply <a href="/articles/disabling-menu-entries-in-deployed-docked-figures#respond">leave a comment</a> below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures">Disabling menu entries in deployed docked figures</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/docking-figures-in-compiled-applications" rel="bookmark" title="Docking figures in compiled applications">Docking figures in compiled applications </a> <small>Figures in compiled applications cannot officially be docked since R2008a, but this can be done using a simple undocumented trick....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps" rel="bookmark" title="Using pure Java GUI in deployed Matlab apps">Using pure Java GUI in deployed Matlab apps </a> <small>Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-9-popup-figures" rel="bookmark" title="Matlab toolstrip – part 9 (popup figures)">Matlab toolstrip – part 9 (popup figures) </a> <small>Custom popup figures can be attached to Matlab GUI toolstrip controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures" rel="bookmark" title="JGraph in Matlab figures">JGraph in Matlab figures </a> <small>JGraph is a powerful open-source Java library that can easily be integrated in Matlab figures. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures/feed</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing menu items part 3</title>
		<link>https://undocumentedmatlab.com/articles/customizing-menu-items-part-3?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-menu-items-part-3</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-menu-items-part-3#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 09 May 2012 18:00:05 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Menubar]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2909</guid>

					<description><![CDATA[<p>Matlab menu items can easily display custom icons, using just a tiny bit of Java magic powder. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3">Customizing menu items part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-2" rel="bookmark" title="Customizing menu items part 2">Customizing menu items part 2 </a> <small>Matlab menu items can be customized in a variety of useful ways using their underlying Java object. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-combobox-items" rel="bookmark" title="Customizing listbox/combobox items">Customizing listbox/combobox items </a> <small>Matlab listboxes can be customized using custom Java cell-renderers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-1" rel="bookmark" title="Customizing menu items part 1">Customizing menu items part 1 </a> <small>Matlab menus can be customized in a variety of undocumented manners - first article of a series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes" rel="bookmark" title="Customizing uitree nodes &#8211; part 1">Customizing uitree nodes &#8211; part 1 </a> <small>This article describes how to customize specific nodes of Matlab GUI tree controls created using the undocumented uitree function...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In the past weeks I&#8217;ve shown how Matlab menus can be customized in a variety of undocumented manners, using HTML, <a target="_blank" href="/articles/customizing-menu-items-part-1/">pure Matlab</a>, and <a target="_blank" href="/articles/customizing-menu-items-part-2/">Java</a>. Today I conclude this mini-series with an article that explains how to use the underlying Java object to customize menu item icons. Menu customizations are explored in depth in section 4.6 of my <a target="_blank" href="/matlab-java-book/">book</a>.</p>
<h3 id="underlying">A reminder: accessing the underlying Java object</h3>
<p>Matlab menus (<i><b>uimenu</b></i>) are basically simple wrappers for the much more powerful and flexible Java Swing <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html"><code>JMenu</code> and <code>JMenuItem</code></a> on which they are based.  Many important functionalities that are available in Java menus are missing from the Matlab <i><b>uimenu</b></i>s.<br />
Getting the Java reference for the figure window&#8217;s main menu is very easy:</p>
<pre lang='matlab'>
jFrame = get(handle(hFig),'JavaFrame');
try
    % R2008a and later
    jMenuBar = jFrame.fHG1Client.getMenuBar;
catch
    % R2007b and earlier
    jMenuBar = jFrame.fFigureClient.getMenuBar;
end
</pre>
<p>There are many customizations that can only be done using the Java handle: setting icons, several dozen callback types, tooltips, background color, font, text alignment, and so on. etc. Interested readers may wish to <i><b>get</b></i>/<i><b>set</b></i>/<i><b>inspect</b></i>/<i><b>methodsview</b></i>/<i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect</a></b></i> the <code>jSave</code> reference handle and/or to read the documentation for <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/6/docs/api/javax/swing/JMenuItem.html"><code>JMenuItem</code></a>. Today&#8217;s article will focus on icon customizations.</p>
<h3 id="simple">Setting simple menu item icons</h3>
<p>Many of Matlab&#8217;s icons reside in either the <i>[matlabroot &#8216;/toolbox/matlab/icons/&#8217;]</i> folder or the <i>[matlabroot &#8216;/java/jar/mwt.jar&#8217;]</i> file (a JAR file is simply a zip file that includes Java classes and resources such as icon images). Let us create icons from the latter, to keep a consistent look-and-feel with the rest of Matlab (we could just as easily use our own external icon files):</p>
<pre lang='matlab'>
% External icon file example
jSave.setIcon(javax.swing.ImageIcon('C:\Yair\save.gif'));
% JAR resource example
jarFile = fullfile(matlabroot,'/java/jar/mwt.jar');
iconsFolder = '/com/mathworks/mwt/resources/';
iconURI = ['jar:file:/' jarFile '!' iconsFolder 'save.gif'];
iconURI = java.net.URL(iconURI);  % not necessary for external files
jSave.setIcon(javax.swing.ImageIcon(iconURI));
</pre>
<p>Note that setting a menu item&#8217;s icon automatically re-aligns all other items in the menu, including those that do not have an icon (an internal bug that was introduced in R2010a causes a misalignment, as shown below):<br />
<center><figure style="width: 230px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Menu item with a custom Icon (R2009b)" src="https://undocumentedmatlab.com/images/uimenu3.png" title="Menu item with a custom Icon (R2009b)" width="230" height="120"/><figcaption class="wp-caption-text">Menu item with a custom <b>Icon</b> (R2009b)</figcaption></figure> &nbsp;&nbsp;&nbsp; <figure style="width: 227px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="...and the same in R2010a onward" src="https://undocumentedmatlab.com/images/uimenu3b.png" title="...and the same in R2010a onward" width="227" height="120"/><figcaption class="wp-caption-text">...and the same in R2010a onward</figcaption></figure></center></p>
<h3 id="checkmark">Checkmark icon</h3>
<p>The empty space on the left of the menu is reserved for the check mark. Each Matlab menu item is check-able, since it is an object that extends the <code>com.mathworks.mwswing.MJCheckBoxMenuItem</code> class. I have not found a way to eliminate this empty space, which is really unnecessary in the File-menu case (it is only actually necessary in the View and Tools menus). Note that if an icon is set for the item, both the icon and the checkmark will be displayed, side by side.<br />
The check mark is controlled by the <b>State</b> property of the Java object (which accepts logical true/false values), or the <b>Checked</b> property of the Matlab handle (which accepts the regular &#8216;on&#8217;/&#8217;off&#8217; string values):</p>
<pre lang='matlab'>
% Set the check mark at the Matlab level
set(findall(hFig,'tag','figMenuFileSave'), 'Checked','on');
% Equivalent - set the checkmark at the Java level
jSave.setState(true);
</pre>
<p><center><figure style="width: 185px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="State = true, Icon = [ ]" src="https://undocumentedmatlab.com/images/uimenu_save_checked1.png" title="State = true, Icon = [ ]" width="185" height="138"/><figcaption class="wp-caption-text"><b>State</b> = true, <b>Icon</b> = &#091; &#093;</figcaption></figure> &nbsp;&nbsp;&nbsp; <figure style="width: 205px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="State = true, Icon = custom" src="https://undocumentedmatlab.com/images/uimenu_save_checked2.png" title="State = true, Icon = custom" width="205" height="137"/><figcaption class="wp-caption-text"><b>State</b> = true, <b>Icon</b> = custom</figcaption></figure></center></p>
<h3 id="custom">Customizing menu icons</h3>
<p>Icons can be customized: modify the gap between the icon and the label with the <b>IconTextGap</b> property (default = 4 [pixels]); place icons to the right of the label by setting <b>HorizontalTextPosition</b> to <code>jSave.LEFT</code> (=2), or centered using <code>jSave.CENTER</code> (=0). Note that the above-mentioned misalignment bug does not appear in these cases:<br />
<center><figure style="width: 222px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="jSave.setHorizontalTextPosition(jSave.LEFT)" src="https://undocumentedmatlab.com/images/uimenu4.png" title="jSave.setHorizontalTextPosition(jSave.LEFT)" width="222" height="121"/><figcaption class="wp-caption-text"><code>jSave.setHorizontalTextPosition<br />(jSave.LEFT)</code></figcaption></figure> &nbsp;&nbsp;&nbsp; <figure style="width: 223px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="jSave.setHorizontalTextPosition(jSave.CENTER)" src="https://undocumentedmatlab.com/images/uimenu5.png" title="jSave.setHorizontalTextPosition(jSave.CENTER)" width="223" height="120"/><figcaption class="wp-caption-text"><code>jSave.setHorizontalTextPosition<br />(jSave.CENTER)</code></figcaption></figure></center><br />
Note how the label text can be seen through (or on top of) the icon when it is centered. This feature can be used to create stunning menu effects as shown below. Note how the width and height of the menu item automatically increased to accommodate my new 77&#215;31 icon size (icons are normally sized 16&#215;16 pixels):<br />
<center><figure style="width: 285px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Overlaid icon (HorizontalTextPosition = CENTER)" src="https://undocumentedmatlab.com/images/uimenu6.png" title="Overlaid icon (HorizontalTextPosition = CENTER)" width="285" height="136"/><figcaption class="wp-caption-text">Overlaid icon (<b>HorizontalTextPosition</b> = CENTER)</figcaption></figure></center><br />
To resize an icon programmatically before setting it in a Java component, we can use the following example:</p>
<pre lang='matlab'>
myIcon = fullfile(matlabroot,'/toolbox/matlab/icons/matlabicon.gif');
imageToolkit = java.awt.Toolkit.getDefaultToolkit;
iconImage = imageToolkit.createImage(myIcon);
iconImage = iconImage.getScaledInstance(32,32,iconImage.SCALE_SMOOTH);
jSave.setIcon(javax.swing.ImageIcon(iconImage));
</pre>
<p>Remember when rescaling images, particularly small ones with few pixels, that it is always better to shrink than to enlarge images: enlarging a small icon image might introduce a significant pixelization effect:<br />
<center><figure style="width: 90px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="16x16 icon image resized to 32x32" src="https://undocumentedmatlab.com/images/button_icon2.png" title="16x16 icon image resized to 32x32" width="90" height="90"/><figcaption class="wp-caption-text">16x16 icon image resized to 32x32</figcaption></figure></center><br />
Separate icons can be specified for a different appearance during mouse hover (<b>RolloverIcon</b>; requires <b>RolloverEnabled</b>=1), item click/press (<b>PressedIcon</b>), item selection (<b>SelectedIcon</b>, <b>RolloverSelectedIcon</b>, <b>DisabledSelectedIcon</b>), and disabled menu item (<b>DisabledIcon</b>). All these properties are empty ([]) by default, which applies a predefined default variation (image color filter) to the main item&#8217;s Icon. For example, let us modify <b>DisabledIcon</b>:</p>
<pre lang='matlab'>
myIcon = 'C:\Yair\Undocumented Matlab\Images\save_disabled.gif';
jSaveAs.setDisabledIcon(javax.swing.ImageIcon(myIcon));
jSaveAs.setEnabled(false);
</pre>
<p><center><figure style="width: 120px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Enabled, main Icon" src="https://undocumentedmatlab.com/images/uimenu7a.png" title="Enabled, main Icon" width="120" height="135"/><figcaption class="wp-caption-text">Enabled, main <b>Icon</b></figcaption></figure> &nbsp;&nbsp;&nbsp; <figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Disabled, default Icon variation" src="https://undocumentedmatlab.com/images/uimenu7b.png" title="Disabled, default Icon variation" width="120" height="135"/><figcaption class="wp-caption-text">Disabled, default <b>Icon</b> variation</figcaption></figure> &nbsp;&nbsp;&nbsp; <figure style="width: 170px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Disabled, custom DisabledIcon" src="https://undocumentedmatlab.com/images/uimenu7c.png" title="Disabled, custom DisabledIcon" width="120" height="135"/><figcaption class="wp-caption-text">Disabled, custom <b>DisabledIcon</b></figcaption></figure></center><br />
Note the automatic graying of disabled menu items, including their icon. This effect can also be achieved programmatically using the static methods in <code>com.mathworks.mwswing.IconUtils</code>: <i>changeIconColor(), createBadgedIcon(), createGhostedIcon()</i>, and <i>createSelectedIcon()</i>. When we use a non-default custom <b>DisabledIcon</b>, it is used instead of the gray icon variant.<br />
This concludes my mini-series of customizing menus in Matlab. If you have used any nifty customization that I have not mentioned, please post a comment about it <a href="/articles/customizing-menu-items-part-3/#respond">below</a>.<br />
<span class="alignleft" id="ken_mike"><img loading="lazy" decoding="async" alt="Ken &#038; Mike" src="https://undocumentedmatlab.com/images/ken_and_mike.png" title="Ken &#038; Mike" width="98" height="83"/></span>In an unrelated note, I would like to extend good wishes to Mike Katz, who has left the MathWorks mobile development team to join Kinvey a few days ago. Mike has been with MathWorks since 2005 and has been responsible for maintaining the official <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/">MATLAB Desktop blog</a>, together with <a target="_blank" href="/articles/gui-integrated-browser-control/">Ken Orr</a>. I&#8217;m not sure yet which direction the Desktop blog will take, and by whom, but in any case it won&#8217;t be the same. You&#8217;re both missed, Mike &#038; Ken!</p>
<p />&nbsp;</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3">Customizing menu items part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-2" rel="bookmark" title="Customizing menu items part 2">Customizing menu items part 2 </a> <small>Matlab menu items can be customized in a variety of useful ways using their underlying Java object. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-combobox-items" rel="bookmark" title="Customizing listbox/combobox items">Customizing listbox/combobox items </a> <small>Matlab listboxes can be customized using custom Java cell-renderers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-1" rel="bookmark" title="Customizing menu items part 1">Customizing menu items part 1 </a> <small>Matlab menus can be customized in a variety of undocumented manners - first article of a series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes" rel="bookmark" title="Customizing uitree nodes &#8211; part 1">Customizing uitree nodes &#8211; part 1 </a> <small>This article describes how to customize specific nodes of Matlab GUI tree controls created using the undocumented uitree function...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-menu-items-part-3/feed</wfw:commentRss>
			<slash:comments>39</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing menu items part 2</title>
		<link>https://undocumentedmatlab.com/articles/customizing-menu-items-part-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-menu-items-part-2</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-menu-items-part-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 May 2012 11:57:38 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Menubar]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2902</guid>

					<description><![CDATA[<p>Matlab menu items can be customized in a variety of useful ways using their underlying Java object. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-2">Customizing menu items part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3" rel="bookmark" title="Customizing menu items part 3">Customizing menu items part 3 </a> <small>Matlab menu items can easily display custom icons, using just a tiny bit of Java magic powder. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-combobox-items" rel="bookmark" title="Customizing listbox/combobox items">Customizing listbox/combobox items </a> <small>Matlab listboxes can be customized using custom Java cell-renderers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-1" rel="bookmark" title="Customizing menu items part 1">Customizing menu items part 1 </a> <small>Matlab menus can be customized in a variety of undocumented manners - first article of a series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-editboxes" rel="bookmark" title="Customizing editboxes">Customizing editboxes </a> <small>Matlab's editbox can be customized in many useful manners...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I <a target="_blank" href="/articles/customizing-menu-items-part-1/">explained</a> how to customize Matlab&#8217;s menu items using some undocumented tricks that do not need Java. Today I will show how using just a tiny bit of Java magic powder we can add much more complex customizations to menu items. Menu customizations are explored in depth in section 4.6 of my <a target="_blank" href="/matlab-java-book/">book</a>.</p>
<h3 id="underlying">Accessing the underlying Java object</h3>
<p>Matlab menus (<i><b>uimenu</b></i>) are basically simple wrappers for the much more powerful and flexible Java Swing <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html"><code>JMenu</code> and <code>JMenuItem</code></a> on which they are based.  Many important functionalities that are available in Java menus are missing from the Matlab <i><b>uimenu</b></i>s.<br />
Getting the Java reference for the figure window&#8217;s main menu is very easy:</p>
<pre lang='matlab'>
jFrame = get(handle(hFig),'JavaFrame');
try
    % R2008a and later
    jMenuBar = jFrame.fHG1Client.getMenuBar;
catch
    % R2007b and earlier
    jMenuBar = jFrame.fFigureClient.getMenuBar;
end
</pre>
<p>Note that we have used the figure handle&#8217;s hidden <a target="_blank" href="/articles/minimize-maximize-figure-window/#JavaFrame"><b>JavaFrame</b> property</a>, accessed through the reference&#8217;s <i><b>handle</b></i>() wrapper, to prevent an annoying warning message.<br />
There are many customizations that can only be done using the Java handle: setting icons, several dozen callback types, tooltips, background color, font, text alignment, and so on. etc. Interested readers may wish to <i><b>get</b></i>/<i><b>set</b></i>/<i><b>inspect</b></i>/<i><b>methodsview</b></i>/<i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect</a></b></i> the <code>jSave</code> reference handle and/or to read the documentation for <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/6/docs/api/javax/swing/JMenuItem.html"><code>JMenuItem</code></a>. Some useful examples are provided below.</p>
<h3 id="dynamic">Dynamic menu behavior</h3>
<p>As a first example of Java-based customization, let us add DHTML-like behavior to the menu, such that the menu items will automatically be displayed when the mouse hovers over the item, without waiting for a user mouse click. First, get the <code>jMenuBar</code> reference as described above. Now, set the <b>MouseEnteredCallback</b> to automatically simulate a user mouse click on each menu item using its <i>doClick()</i> method. Setting the callback should be done separately to each of the top-level menu components:</p>
<pre lang='matlab'>
for menuIdx = 1 : jMenuBar.getComponentCount
    jMenu = jMenuBar.getComponent(menuIdx-1);
    hjMenu = handle(jMenu,'CallbackProperties');
    set(hjMenu,'MouseEnteredCallback','doClick(gcbo)');
end
</pre>
<p>Note that using this mechanism may be awkward if the top-level menu does not have a sub-menu but is rather a stand-alone menu item. For example, if the top-level menu-item &#8220;Help&#8221; is a stand-alone menu button (i.e., there are no help menu-items, just the single Help item), then moving the mouse over this item will trigger the help event, although the user did not actually click on the item. To prevent this behavior, we should modify the code snippet above to only work on those menu items that have sub-items.</p>
<h3 id="accelerator">Custom accelerator shortcut keys</h3>
<p>As another example, Matlab automatically assigns a non-modifiable keyboard accelerator key modifier of <ctrl>, while JMenus allow any combination of Alt/Ctrl/Shift/Meta (depending on the platform). Let us modify the default File/Save accelerator key from &#8216;Ctrl-S&#8217; to &#8216;Alt-Shift-S&#8217; as an example. We need a reference for the &#8220;Save&#8221; menu item. Note that unlike regular Java components, menu items are retrieved using the <i>getMenuComponent()</i> method and not <i>getComponent()</i>:</p>
<pre lang='matlab'>
% File main menu is the first main menu item => index=0
jFileMenu = jMenuBar.getComponent(0);
% Save menu item is the 5th menu item (separators included)
jSave = jFileMenu.getMenuComponent(4); %Java indexes start with 0!
inspect(jSave) 	% just to be sure: label='Save' => good!
% Finally, set a new accelerator key for this menu item:
jAccelerator = javax.swing.KeyStroke.getKeyStroke('alt shift S');
jSave.setAccelerator(jAccelerator);
</pre>
<p>That is all there is to it – the label is modified automatically to reflect the new keyboard accelerator key. More info on setting different combinations of accelerator keys and modifiers can be found in the official Java documentation for <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/6/docs/api/javax/swing/KeyStroke.html#getKeyStroke%28java.lang.String%29"><code>KeyStroke</code></a>.<br />
<center><figure style="width: 202px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Modification of menu item accelerator and tooltip" src="https://undocumentedmatlab.com/images/uimenu1.png" title="Modification of menu item accelerator and tooltip" width="202" height="200"/><figcaption class="wp-caption-text">Modification of menu item accelerator and tooltip</figcaption></figure></center><br />
Note that the Save menu-item reference can only be retrieved after opening the File menu at least once earlier; otherwise, an exception will be thrown when trying to access the menu item. The File menu does NOT need to remain open – it only needs to have been opened sometime earlier, for its menu items to be rendered. This can be done either interactively (by selecting the File menu) or programmatically:</p>
<pre lang='matlab'>
% Simulate mouse clicks to force the File main-menu to open & close
jFileMenu.doClick; % open the File menu
jFileMenu.doClick; % close the menu
% Now the Save menu is accessible:
jSave = jFileMenu.getMenuComponent(4);
</pre>
<h3 id="tooltip">Tooltip and highlight</h3>
<p>For some unknown reason, MathWorks did not include a tooltip property in its Matlab menu handle, contrary to all the other Matlab GUI components. So we must use the Java handle, specifically the <b>ToolTipText</b> property:</p>
<pre lang='matlab'>jSave.setToolTipText('modified menu item with tooltip');</pre>
<p>Java menu items also contain a property called <b>Armed</b>, which is a logical value (default=false). When turned on, the menu item is highlighted just as when it is selected (see the <i>Save As&#8230;</i> menu item in the screenshot above). On a Windows system, this means a blue background:</p>
<pre lang='matlab'>jSave.setArmed(true);</pre>
<p>When the item is actually selected and then de-selected, <b>Armed</b> reverts to a false (off) value. Alternating the <b>Armed</b> property value can achieve an effect of flashing the menu item.</p>
<h3 id="callbacks">Callbacks</h3>
<p>In addition to the standard Swing control callbacks discussed in an <a target="_blank" href="/articles/uicontrol-callbacks/">earlier article</a>, menu items possess several additional callbacks that are specific to menu items, including:</p>
<ul>
<li><b>ActionPerformedCallback</b> – fired when the menu item is invoked</li>
<li><b>StateChangedCallback</b> – fired when the menu item is selected or deselected</li>
<li><b>MenuDragMouseXXXCallback</b> (XXX=Dragged/Entered/Exited/Released) – fired when the menu item is dragged, for the corresponding event</li>
<li><b>MenuKeyXXXCallback</b> (XXX=Pressed/Released/Typed) – fired when a keyboard click event occurs (the menu item&#8217;s accelerator was typed)</li>
</ul>
<p>Using these callbacks, together with the 30-odd standard Swing callbacks, we can control our menu&#8217;s behavior to a much higher degree than possible using the standard Matlab handle.<br />
Next week, I will conclude this mini-series with an article explaining how to customize menu item icons.</ctrl></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-2">Customizing menu items part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3" rel="bookmark" title="Customizing menu items part 3">Customizing menu items part 3 </a> <small>Matlab menu items can easily display custom icons, using just a tiny bit of Java magic powder. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-combobox-items" rel="bookmark" title="Customizing listbox/combobox items">Customizing listbox/combobox items </a> <small>Matlab listboxes can be customized using custom Java cell-renderers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-1" rel="bookmark" title="Customizing menu items part 1">Customizing menu items part 1 </a> <small>Matlab menus can be customized in a variety of undocumented manners - first article of a series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-editboxes" rel="bookmark" title="Customizing editboxes">Customizing editboxes </a> <small>Matlab's editbox can be customized in many useful manners...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-menu-items-part-2/feed</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
	</channel>
</rss>
