<?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>PixelBounds &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/pixelbounds/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 06 Jan 2010 21:06:33 +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>FindJObj &#8211; find a Matlab component&#039;s underlying Java object</title>
		<link>https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=findjobj-find-underlying-java-object</link>
					<comments>https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 06 Jan 2010 21:06:33 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[PixelBounds]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=892</guid>

					<description><![CDATA[<p>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.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object</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/assessing-java-object-size-in-matlab" rel="bookmark" title="Assessing Java object size in Matlab">Assessing Java object size in Matlab </a> <small>Java object sizes are not reported by Matlab, but we can still estimate them using two free external utilities. ...</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-findjobj" rel="bookmark" title="Faster findjobj">Faster findjobj </a> <small>the ubiquitous findjobj utility has been significantly improved for speed for the most common use case. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/font-selection-components" rel="bookmark" title="Font selection components">Font selection components </a> <small>Several built-in components enable programmatic font selection in Matlab GUI - this article explains how. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In a previous post, I explained that all Matlab GUI (except the axes plotting engine) is based on Java components, and showed how we can use this information to <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">display HTML contents in Matlab <b><i>uicontrol</i></b>s</a>. In <a target="_blank" href="/articles/tag/findjobj/">other posts</a>, I have shown how a utility called <b><i>findjobj</i></b> can be used to access the underlying Java components to enable customizations that are unavailable in standard Matlab: <a target="_blank" href="/articles/setting-line-position-in-edit-box-uicontrol/">setting the line location in an edit-box</a>, <a target="_blank" href="/articles/button-customization/">customizing button appearance</a>, <a target="_blank" href="/articles/uicontrol-callbacks/">setting uicontrol callbacks</a>, or <a target="_blank" href="/articles/setting-listbox-mouse-actions/">setting list-box mouse actions</a>. I have also shown how <b><i>findjobj</i></b> can be used to display the component hierarchy of complex Matlab containers such as the <a target="_blank" href="/articles/figure-toolbar-customizations/">figure window</a>, <a target="_blank" href="/articles/guide-customization/">GUIDE</a> or the <a target="_blank" href="/articles/accessing-the-matlab-editor/">Editor</a>.<br />
The time is therefore well overdue for a formal introduction of <b><i>findjobj</i></b>, explaining its uses and internal mechanism. Of course, readers are welcome to continue using <b><i>findjobj</i></b> as a black-box utility, but I think important insight can be gained from understanding its inner details. <b><i>Findjobj</i></b>&#8216;s code is available for free download on the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">MathWorks File Exchange</a>. It is one of my favorite submissions and is apparently well-liked by users, being highly reviewed and highly downloaded.<br />
<b><i>Findjobj</i></b> has two main purposes:</p>
<ol>
<li>Find the underlying Java object reference of a given Matlab handle &#8211; Historically this was the original purpose, hence the utility&#8217;s name. <b><i>Findjobj</i></b> was meant to extend Matlab&#8217;s standard <b><i>findobj</i></b> function, which does not expose Java components.</li>
<li>Display a container&#8217;s internal components hierarchy in a graphical user interface, to facilitate visualization of complex containers. This was later extended to also display and allow modification of the sub-components&#8217; properties and callbacks.</li>
</ol>
<p>Today I will focus on the first (programmatic) aspect;  next week I will describe the second (GUI) aspect.<br />
<b><i>Findjobj</i></b>&#8216;s heart is finding a control&#8217;s underlying Java handle. Unfortunately, this is not exposed by Matlab except in very rare cases. As hard as I tried, I could not find a way to directly access the underlying Java-peer handle. I therefore resorted to getting the control&#8217;s enclosing Java frame (window) reference, and then working down its sub-components hierarchy until finding the Java object(s) which satisfy the position and/or class criteria. To get the enclosing Java frame (aka <i>TopLevelAncestor</i>), I use the Matlab figure&#8217;s undocumented <b>JavaFrame</b> property. Using this property issues a standard warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release. Since it worked so far, I have turned off this warning in <b><i>findjobj</i></b>&#8216;s code, but note that this code may well fail in some future Matlab version. If and when <b>JavaFrame</b> does become obsolete, be sure to look in this blog for workarounds…<br />
Traversing the frame&#8217;s hierarchy presents several challenges: Main-menu items are accessed using different functions than other Swing components or sub-containers, and are not automatically accessible until first displayed. I have overcome this latter challenge by simulating a menu-open action in case menus should be searched (this is off by default since it takes several seconds and also changes the GUI focus). For &#8220;regular&#8221; sub-containers, sometimes we need to loop over <i>getComponent(&#8230;)</i> and in some other cases over <i>getChildAt(&#8230;)</i>.<br />
Another challenge was presented by the fact that Java positions start at (0,0) in the <u>top</u> left corner increasing rightward and <u>downward</u>, rather than starting at (1,1) in the bottom left and increasing upward as in Matlab. Moreover, Java positions are always pixel-based and relative to their parent container, which is different from Matlab (if the Matlab units is &#8216;pixels&#8217; then the value is absolute; if &#8216;normalized&#8217; then it returns a non-pixel value). To further complicate matters, some Matlab controls have a different size than their Java counterparts: some controls have a 5-pixel margins while others not, some controls are shifted by a pixel or two from their container&#8217;s border (for a total offset of up to 7 pixels), while some controls (such as popup-menus) have an entirely different reported size. In theory, we could use the Matlab component&#8217;s undocumented <b>PixelBounds</b> property (much faster than <b><i>getpixelposition</i></b>), but unfortunately <b>PixelBounds</b> turns out to be unreliable and returns erroneous values in many cases. Finally, different Java containers/components have different ways of returning their position: for some it is a <i>getLocation()</i> method, for others it is <i>getX()/getY()</i> and for others it is the <b>X</b> and <b>Y</b> properties (that sometimes have no corresponding <i>getX()/getY()</i> accessor methods!).<br />
Having finally overcome all these challenges (and quite a few smaller ones, documented within the source code), I have wrapped the algorithm in a function interface that tries to emulate <b><i>findobj</i></b>&#8216;s. Using <b><i>findjobj</i></b> can now be as easy as:</p>
<pre lang="Matlab">
% Modify the mouse cursor when over the button
hButton = uicontrol('string','click me!');
jButton = findjobj(hButton);
jButton.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR))
</pre>
<p><center><figure style="width: 250px" class="wp-caption aligncenter"><img decoding="async" alt="Modified uicontrol cursor - a Java property" src="https://undocumentedmatlab.com/images/button_cursor_hand.png" title="Modified uicontrol cursor - a Java property" width="105" height="66" /><figcaption class="wp-caption-text">Modified uicontrol cursor - a Java property</figcaption></figure></center><br />
&#8230;or as complex as:</p>
<pre lang="Matlab">
% Find all non-button controls with the specified label
jControls = findjobj('property',{'text','click me!'}, 'not','class','button');
</pre>
<p>Space here is limited and <b><i>findjobj</i></b> is over 2500 lines long, so I have obviously not covered everything. I encourage you to <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">download the utility</a> and explore the code, and I gladly welcome your feedback.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object</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/assessing-java-object-size-in-matlab" rel="bookmark" title="Assessing Java object size in Matlab">Assessing Java object size in Matlab </a> <small>Java object sizes are not reported by Matlab, but we can still estimate them using two free external utilities. ...</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-findjobj" rel="bookmark" title="Faster findjobj">Faster findjobj </a> <small>the ubiquitous findjobj utility has been significantly improved for speed for the most common use case. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/font-selection-components" rel="bookmark" title="Font selection components">Font selection components </a> <small>Several built-in components enable programmatic font selection in Matlab GUI - this article explains how. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object/feed</wfw:commentRss>
			<slash:comments>69</slash:comments>
		
		
			</item>
		<item>
		<title>Displaying hidden handle properties</title>
		<link>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=displaying-hidden-handle-properties</link>
					<comments>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 05 May 2009 23:03:55 +0000</pubDate>
				<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[OuterPosition]]></category>
		<category><![CDATA[PixelBounds]]></category>
		<category><![CDATA[schema.class]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=237</guid>

					<description><![CDATA[<p>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties">Displaying hidden handle properties</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/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Matlab Handle Graphics (HG) is a great way to manipulate GUI objects. HG handles often have some undocumented hidden properties. One pretty well-known example is the <strong>JavaFrame</strong> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object.  We can use hidden properties just like any other handle property, using the built-in <b><i>get</i></b> and <b><i>set</i></b> functions.<br />
But how can we know about these properties? Here are two methods to do so. Like the hidden properties, these two methods are themselves undocumented&#8230;<br />
1. use the desktop&#8217;s hidden <strong>HideUndocumented</strong> property:</p>
<blockquote>
<pre><span style="color: #000000">set(0,</span><span style="color: #800080">'HideUndocumented','off'</span><span style="color: #000000">);</pre>
</blockquote>
<p>From now on, when displaying handle properties using <b><i>get</i></b> and <b><i>set</i></b> you&#8217;ll see the hidden properties.<br />
Note that some of the properties might display a warning indication:</p>
<blockquote>
<pre><span style="color: #000000">>> get(gcf)</span>
	Alphamap = [ (1 by 64) double array]
	BackingStore = on
	CloseRequestFcn = closereq
	Color = [0.8 0.8 0.8]
	Colormap = [ (64 by 3) double array]
	CurrentAxes = []
	CurrentCharacter =
	CurrentKey =
	CurrentModifier = [ (1 by 0) cell array]
	CurrentObject = []
	CurrentPoint = [0 0]
	Dithermap<span style="color: #800000">Warning: figure Dithermap is no longer useful
 with TrueColor displays, and will be removed in a future release.</span>
 = [ (64 by 3) double array]
        ...
</pre>
</blockquote>
<p>2. Access the properties&#8217; definition in the handle&#8217;s class definition:</p>
<blockquote>
<pre><span style="color: #000000">>> ch = classhandle(handle(gcf));
>> props = get(ch,</span><span style="color: #800080">'Properties'</span><span style="color: #000000">);
>> propsVisibility = get(props,</span><span style="color: #800080">'Visible'</span><span style="color: #000000">)';
>> hiddenProps = props(strcmp(propsVisibility,</span><span style="color: #800080">'off'</span><span style="color: #000000">));
>> sort(get(hiddenProps,</span><span style="color: #800080">'Name'</span><span style="color: #000000">))</span>
ans =
    'ALimInclude'
    'ActivePositionProperty'
    'ApplicationData'
    'BackingStore'
    'Behavior'
    'CLimInclude'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'ExportTemplate'
    'HelpFcn'
    'HelpTopicKey'
    'HelpTopicMap'
    'IncludeRenderer'
    'JavaFrame'
    'OuterPosition'
    'PixelBounds'
    'PrintTemplate'
    'Serializable'
    'ShareColors'
    'UseHG2'
    'WaitStatus'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
</pre>
</blockquote>
<p>Different HG handles have different hidden properties. Not all these properties are useful. For example, I have found the <strong>PixelBounds</strong> property to be problematic &#8211; (it sometimes reports incorrect values!). Other properties (like <strong>Dithermap</strong> or <strong>ShareColors</strong>) are deprecated and display a warning wherever they are accessed.<br />
But every so often we find a hidden property that can be of some actual benefit. Let&#8217;s take the figure handle&#8217;s <strong>OuterPosition</strong> property for example. It provides the figure&#8217;s external position values, including the space used by the window frame, toolbars etc., whereas the regular documented <strong>Position</strong> property only reports the <b>internal</b> bounds:</p>
<blockquote>
<pre><span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'pos'</span>)
ans =
   232   246   560   420
<span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'outer'</span>)
ans =
   228   242   568   502
</pre>
</blockquote>
<p>In future posts I will sometimes use such hidden properties. You can find the latest list by looking at this blog&#8217;s <a href="/articles/category/Hidden-property/" target="_blank">&#8220;Hidden property&#8221;</a> category page.<br />
Note: Like the rest of Matlab&#8217;s undocumented items, all hidden properties are undocumented, unsupported and may well change in future Matlab releases so use them with care.<br />
Did you find any useful hidden property? If so, then please leave your finding in the comments section below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties">Displaying hidden handle properties</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/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
	</channel>
</rss>
