<?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>uitools &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/uitools/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 23 Nov 2020 16:40:31 +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>Customizing the standard figure toolbar, menubar</title>
		<link>https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-standard-figure-toolbar-menubar</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 09 Jan 2013 18:00:12 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[Menubar]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3461</guid>

					<description><![CDATA[<p>The standard figure toolbar and menubar can easily be modified to include a list of recently-used files.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar">Customizing the standard figure toolbar, menubar</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-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/modifying-default-toolbar-menubar-actions" rel="bookmark" title="Modifying default toolbar/menubar actions">Modifying default toolbar/menubar actions </a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few days ago, a client asked me to integrate an MRU (most-recently-used) file list in a Matlab GUI window. The naive approach was to add a new &#8220;Recent files&#8221; main menu, but this would look bad. Today I explain how to integrate the MRU list into the toolbar&#8217;s standard &#8220;Open File&#8221; button, as well as into the standard &#8220;File&#8221; main menu.</p>
<h3 id="Menubar">Customizing the standard &#8220;File&#8221; main menu</h3>
<p>Note: this relies on earlier articles about <a target="_blank" href="/articles/tag/menubar/">customizing the figure menubar</a>, so if you are not comfortable with this topic you might benefit from reading these earlier articles.<br />
Customizing the standard &#8220;File&#8221; main menu is easy. First, let&#8217;s find the &#8220;File&#8221; main menu&#8217;s handle, and add an MRU sub-menu directly to it:</p>
<pre lang='matlab'>
hFileMenu = findall(gcf, 'tag', 'figMenuFile');
hMruMenu = uimenu('Label','Recent files', 'Parent',hFileMenu);
</pre>
<p>Our new MRU menu item is created at the end (in this case, at the bottom of the &#8220;File&#8221; main menu list). Let&#8217;s move it upward, between &#8220;New&#8221; and &#8220;Open&#8230;&#8221;, by reordering <code>hFileMenu</code>&#8216;s <b>Children</b> menu items:</p>
<pre lang='matlab'>
hAllMenuItems = allchild(hFileMenu);
set(hFileMenu, 'Children',fliplr(hAllMenuItems([2:end-1,1,end])));  % place in 2nd position, just above the "Open" item
</pre>
<p>Now let&#8217;s fix the &#8220;Open&#8230;&#8221; menu item&#8217;s callback to point to our custom <i>openFile()</i> function (unfortunately, the &#8220;Open&#8230;&#8221; menu item has no tag, so we must rely on its label to get its handle):</p>
<pre lang='matlab'>
hOpenMenu = findall(hFileMenu, 'Label', '&Open...');
set(hOpenMenu, 'Callback',@openFile);
</pre>
<p>Finally, let&#8217;s add the MRU list as a sub-menu of the new <code>hMruMenu</code>. I assume that we have a <i>getMRU()</i> function in our code, which returns a cell-array of filenames:</p>
<pre lang='matlab'>
% Add the list of recent files, one item at a time
filenames = getMRU();
for fileIdx = 1 : length(filenames)
    uimenu(hMruMenu, 'Label',filenames{fileIdx}, 'Callback',{@openFile,filenames{fileIdx}});
end
</pre>
<p><center><figure style="width: 445px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" alt="Modified standard figure menu-bar" src="https://undocumentedmatlab.com/images/Menubar_File_Open.png" title="Modified standard figure menu-bar" width="445" height="182" /><figcaption class="wp-caption-text">Modified standard figure menu-bar</figcaption></figure></center><br />
<span id="more-3461"></span><br />
Clicking the main &#8220;Open&#8230;&#8221; menu item calls our <i>openFile()</i> function without the optional filename input argument, while selecting one of the MRU files will call the <i>openFile()</i> function with that specific filename as input. The <i>openFile()</i> function could be implemented something like this:</p>
<pre lang='matlab'>
% Callback for the open-file functionality (toolbar and menubar)
function openFile(hObject,eventData,filename)
    % If no filename specified, ask for it from the user
    if nargin < 3
        filename = uigetfile({'*.csv','Data files (*.csv)'}, 'Open data file');
        if isempty(filename) || isequal(filename,0)
            return;
        end
    end
    % Open the selected file and read the data
    data = readDataFile(filename);
    % Update the display
    updateGUI(data)
end
</pre>
<p>We can take this idea even further by employing <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">HTML formatting</a>, as I have shown in my <a target="_blank" href="/articles/customizing-menu-items-part-1/">first article of the menubar mini-series</a>:<br />
<center><figure style="width: 411px" class="wp-caption aligncenter"><img decoding="async" alt="HTML-rendered menu items" src="https://undocumentedmatlab.com/images/uimenu2b.png" title="HTML-rendered menu items" width="411" height="246"/><figcaption class="wp-caption-text">HTML-rendered menu items</figcaption></figure></center></p>
<h3 id="Toolbar">Customizing the standard toolbar's "Open File" button</h3>
<p>Note: this relies on earlier articles about <a target="_blank" href="/articles/tag/toolbar/">customizing the figure toolbar</a>, so if you are not comfortable with this topic you might benefit from reading these earlier articles.<br />
The basic idea here is to replace the standard toolbar's "Open File" pushbutton with a new <a target="_blank" href="/articles/uisplittool-uitogglesplittool/">uisplittool</a> button that will contain the MRU list in its picker-menu.<br />
The first step is to get the handle of the toolbar's "Open File" button:</p>
<pre lang='matlab'>
hOpen = findall(gcf, 'tooltipstring', 'Open File');
hOpen = findall(gcf, 'tag', 'Standard.FileOpen');  % Alternative
</pre>
<p>The second alternative is better for non-English Matlab installations where the tooltip text may be different, or in cases where we might have another GUI control with this specific tooltip. On the other hand, the <code>'Standard.FileOpen'</code> tag may be different in different Matlab releases. So choose whichever option is best for your specific needs.<br />
Assuming we have a valid (non-empty) <code>hOpen</code> handle, we get its properties data for later use:</p>
<pre lang='matlab'>
open_data = get(hOpen);
hToolbar = open_data.Parent;
</pre>
<p>We have all the information we need, so we can now simply delete the existing toolbar open button, and create a new split-button with the properties data that we just got:</p>
<pre lang='matlab'>
delete(hOpen);
hNewOpen = uisplittool('Parent',hToolbar, ...
                       'CData',open_data.CData, ...
                       'Tooltip',open_data.TooltipString, ...
                       'ClickedCallback',@openFile);
</pre>
<p>As with the menubar, the button is now created, but it appears on the toolbar&#8217;s right edge. Let&#8217;s move it to the far left. We could theoretically reorder <code>hToolbar</code>&#8216;s <b>Children</b> as for the menubar above, but Matlab has an internal bug that causes some toolbar buttons to misbehave upon rearranging. Using Java solves this:</p>
<pre lang='matlab'>
drawnow;  % this innocent drawnow is *very* important, otherwise Matlab might crash!
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jButtons = jToolbar.getComponents;
jToolbar.setComponentZOrder(jButtons(end),2);  % Move to the position between "New" and "Save"
jToolbar.revalidate;  % update the toolbar's appearance (drawnow will not do this)
</pre>
<p>Finally, let&#8217;s add the list of recent files to the new split-button&#8217;s picker menu:</p>
<pre lang='matlab'>
% (Use the same list of filenames as for the menubar's MRU list)
jNewOpen = get(hNewOpen,'JavaContainer');
jNewOpenMenu = jNewOpen.getMenuComponent;
for fileIdx = 1 : length(filenames)
    jMenuItem = handle(jNewOpenMenu.add(filenames{fileIdx}),'CallbackProperties');
    set(jMenuItem,'ActionPerformedCallback',{@openFile,filenames{fileIdx}});
end
</pre>
<p><center><figure style="width: 445px" class="wp-caption aligncenter"><img decoding="async" alt="Modified standard figure toolbar" src="https://undocumentedmatlab.com/images/Toolbar_Open_File.png" title="Modified standard figure toolbar" width="447" height="143" /><figcaption class="wp-caption-text">Modified standard figure toolbar</figcaption></figure></center><br />
Clicking the main Open button calls our <i>openFile()</i> function without the optional filename input argument, while clicking the picker button (to the right of the main Open button) and selecting one of the files will call the <i>openFile()</i> function with that specific filename as input.<br />
That&#8217;s it. Quite painless in fact. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar">Customizing the standard figure toolbar, menubar</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-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/modifying-default-toolbar-menubar-actions" rel="bookmark" title="Modifying default toolbar/menubar actions">Modifying default toolbar/menubar actions </a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar/feed</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title>Uitable customization report</title>
		<link>https://undocumentedmatlab.com/articles/uitable-customization-report?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitable-customization-report</link>
					<comments>https://undocumentedmatlab.com/articles/uitable-customization-report#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 03 Aug 2011 18:00:25 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<category><![CDATA[uitable report]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2396</guid>

					<description><![CDATA[<p>Matlab's uitable can be customized in many different ways. A detailed report explains how. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-customization-report">Uitable customization report</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/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/treetable" rel="bookmark" title="treeTable">treeTable </a> <small>A description of a sortable, groupable tree-table control that can be used in Matlab is provided. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-3-basic-customization" rel="bookmark" title="Matlab toolstrip – part 3 (basic customization)">Matlab toolstrip – part 3 (basic customization) </a> <small>Matlab toolstrips can be created and customized in a variety of ways. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In last week&#8217;s report about <a target="_blank" href="/articles/uitable-sorting/"><i><b>uitable</b></i> sorting</a>, I offered a report that I have written which covers <i><b>uitable</b></i> customization in detail. Several people have asked for more details about the contents of this report. This is a reasonable request, and so in today&#8217;s post I will discuss in a bit more detail the highlights of what can be achieved to customize Matlab <i><b>uitable</b></i>s. For the fine details, well, <a target="_blank" rel="nofollow" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&#038;business=altmany@gmail.com&#038;currency_code=USD&#038;amount=29&#038;return=&#038;item_name=Matlab-uitable-report">get my uitable report</a> (45 pages PDF, $29).</p>
<h3 id="Introduction">1. Introduction</h3>
<p>Here I discuss the evolution of the <i><b>uitable</b></i> control over the past decade, from its initially semi-documented status to today. I explain the similarities and differences between the control&#8217;s versions and explain how they can both be accessed today.</p>
<p>I also provide references to online resources for both Matlab&#8217;s <i><b>uitable</b></i>&#8216;s underlying Java components, as well as multiple alternatives using different technologies, that have been used and reported over the years.</p>
<h3 id="Customization">2. Customizing uitable</h3>
<p>In this section I explore the sub-component hierarchy of the <i><b>uitable</b></i> controls. I show how the scrollbar sub-components can be accessed (this will be used in section 4 below), as well as the table header and data grid. This is the entry point for uitable customization.<br />
<center><figure style="width: 312px" class="wp-caption aligncenter"><img decoding="async" alt="annotated uitable sub-components" src="https://undocumentedmatlab.com/images/uitable_new2b.png" title="annotated uitable sub-components" width="312" /><figcaption class="wp-caption-text">annotated <i><b>uitable</b></i> sub-components</figcaption></figure></center></p>
<p>I explain how individual cells can be modified without requiring the entire data set to be updated. This is very important in large data sets, to prevent flicker and improve performance.</p>
<p>I show how HTML can be used to format data cell contents (even images) and tooltips:<br />
<center><figure style="width: 249px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with HTML cell contents and tooltip" src="https://undocumentedmatlab.com/images/uitable2.png" title="uitable with HTML cell contents and tooltip" width="249" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with HTML cell contents and tooltip</figcaption></figure></center><br />
<center><figure style="width: 289px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with cell images" src="https://undocumentedmatlab.com/images/uitable_images.png" title="uitable with cell images" width="289" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with cell images</figcaption></figure></center></p>
<h3 id="Callbacks">3. Cell renderers and cell editors</h3>
<p>This section explains the role of the cell-renderer in the visual appearance of the cell, and of cell-editors in the way that cells interact with the user for data modification. I explain such customizations from the simple (setting a column&#8217;s background color) to the complex (cell-specific tooltips and colors; color-selection cell-editor):<br />
<center><br />
<figure style="width: 590px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with a non-standard cell-renderer" src="https://undocumentedmatlab.com/images/uitable_colored.png" title="uitable with a non-standard cell-renderer" width="590" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with a non-standard cell-renderer</figcaption></figure><br />
<figure style="width: 580px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with a non-standard cell-renderer" src="https://undocumentedmatlab.com/images/uitable5b.png" title="uitable with a non-standard cell-renderer" width="288" /><img decoding="async" alt="uitable with a non-standard cell-editor" src="https://undocumentedmatlab.com/images/uitable_lookup.png" title="uitable with a non-standard cell-editor" width="280" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with a non-standard cell-renderer (left) and cell-editor (right)</figcaption></figure><br />
<figure style="width: 308px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with custom CellRenderer and CellEditor" src="https://undocumentedmatlab.com/images/ColorCellEditor_Renderer.png" title="uitable with custom CellRenderer and CellEditor" width="308" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with custom CellRenderer and CellEditor</figcaption></figure></center><br />
Cell renderers can also be used to set custom text format of cell contents and cell-specific tooltips (note the top table in the following screenshot):<br />
<center><figure style="width: 605px" class="wp-caption aligncenter"><img decoding="async" alt="uitable with custom CellRenderers (note text formats and cell-specific tooltips)" src="https://undocumentedmatlab.com/images/Backtesting-results.png" title="uitable with custom CellRenderers (note text formats and cell-specific tooltips)" width="605" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> with custom CellRenderers (note text formats and cell-specific tooltips)</figcaption></figure></center><br />
(also note the colored table headers in the bottom table)</p>
<h3 id="Callbacks">4. Table callbacks</h3>
<p>This section of my uitable report presents the different callback properties that are settable in the old and new <i><b>uitable</b></i>, for events such as cell selection, data modification, key press, and mouse click. The discussion includes a working code example for validating user input and reverting invalid edits. </p>
<p>The section also includes a discussion of how to avoid and overcome problems that may occur with the callback execution.</p>
<h3 id="Scrollbars">5. Customizing scrollbars, column widths and selection behavior</h3>
<p>This section explains how to control the scrollbars behavior. For example, hiding the horizontal (bottom) scrollbar, automatically displaying it when the data width is larger than the table width. I also show how to control the column widths.</p>
<p>I then show how to customize the data selection policy: Can multiple cells be selected? perhaps only one cell at a time? or maybe a single large interval of cells? &#8211; this is all customizable. I then explain how the selection can be done and accessed programmatically.</p>
<p>Ever wanted to set the cursor on cell A1 after some system event has occurred? &#8211; this will show you how to do it.<br />
Ever wanted to use non-standard selection colors (background/foreground)? &#8211; this can also be done.</p>
<h3 id="Sorting">6. Data sorting</h3>
<p>Table sorting was discussed in last week&#8217;s <a target="_blank" href="/articles/uitable-sorting/">article</a>. This section expands on that article, and explains how the sorting can be customized, controlled, and accessed programmatically, and how sorted rows can be retrieved by the user.<br />
<center><figure style="width: 260px" class="wp-caption aligncenter"><img decoding="async" alt="Multi-column sorting with blue sort-order numbers" src="https://undocumentedmatlab.com/images/JIDE_Table_sort3a.png" title="Multi-column sorting with blue sort-order numbers" width="260" /><figcaption class="wp-caption-text">Multi-column sorting with blue sort-order numbers</figcaption></figure></center></p>
<h3 id="Filtering">7. Data filtering</h3>
<p>Data filtering is the ability to filter only a specified sub-set of rows for display (just like in Excel). This section explains how to do it (it&#8217;s so easy!).<br />
<center><figure style="width: 408px" class="wp-caption aligncenter"><img decoding="async" alt="uitable data filtering" src="https://undocumentedmatlab.com/images/004x013b.png" title="uitable data filtering" width="408" /><figcaption class="wp-caption-text"><i><b>uitable</b></i> data filtering</figcaption></figure></center></p>
<h3 id="JIDE">8. JIDE customizations</h3>
<p>The new <i><b>uitable</b></i> is based on an underlying JIDE table. This section explains how we can use this to our advantage for some simple and useful. Customization.</p>
<p>For example: have you wondered some time why is it that columns can only be resized by dragging the tiny divider in the table header? Why can&#8217;t the columns and rows be resized by dragging the grid lines? Well, it turns out that they can, with just a tiny bit of JIDE magic powder, explained here:<br />
<center><figure style="width: 260px" class="wp-caption aligncenter"><img decoding="async" alt="Resizing columns" src="https://undocumentedmatlab.com/images/004x014.png" title="Resizing columns" width="260" /><figcaption class="wp-caption-text">Resizing columns</figcaption></figure></center><br />
Similarly, this section explains how we can use JIDE to merge together adjacent cells:<br />
<center><figure style="width: 260px" class="wp-caption aligncenter"><img decoding="async" alt="Example of two table cell-spans (1x2 and 2x2)" src="https://undocumentedmatlab.com/images/004x016.png" title="Example of two table cell-spans (1x2 and 2x2)" width="260" /><figcaption class="wp-caption-text">Example of two table cell-spans (1x2 and 2x2)</figcaption></figure></center></p>
<p>I also show how to attach a custom context-menu (right-click menu) to the table header row:<br />
<center><figure style="width: 255px" class="wp-caption aligncenter"><img decoding="async" alt="Custom header-row context-menu" src="https://undocumentedmatlab.com/images/uitable_table_header.png" title="Custom header-row context-menu" width="255" /><figcaption class="wp-caption-text">Custom header-row context-menu</figcaption></figure></center></p>
<h3 id="Structure">9. Controlling the table structure (adding/removing rows)</h3>
<p>This section discusses the matter of dynamically adding and removing table rows. While this is easy to do in the old <i><b>uitable</b></i>, this is unfortunately not the case in the new <i><b>uitable</b></i>.</p>
<h3 id="Performance">10. Run-time performance</h3>
<p>This section discusses ways to improve the run-time performance (speed) of <i><b>uitable</b></i>, both new and old. For additional information regarding run-time performance, refer to my book &#8220;<a href="https://undocumentedmatlab.com/books/matlab-performance" target="_blank"><b>MATLAB Performance Tuning</b></a>&#8220;.</p>
<h3 id="Final">11. Final remarks</h3>
<p>Here I present a workaround for a long-time table bug. Also, I present my <i><b>createTable</b></i> utility that wraps table creation in Matlab:<br />
<center><figure style="width: 597px" class="wp-caption aligncenter"><img decoding="async" alt="createTable utility screenshot (note the action buttons, sortable columns, and customized CellEditor)" src="https://undocumentedmatlab.com/images/table.png" title="createTable utility screenshot (note the action buttons, sortable columns, and customized CellEditor)" width="597" /><figcaption class="wp-caption-text"><i><b>createTable</b></i> utility screenshot (note the action buttons, sortable columns, and customized CellEditor)</figcaption></figure></center></p>
<h3 id="JIDE-Grids">Appendix – JIDE Grids</h3>
<p>Finally, this appendix presents an overview of the wide array of components provided by JIDE and available in Matlab. <i><b>uitable</b></i> uses only one of these components (the <code>SortableTable</code>). In fact, there are many more such controls that we can use in our GUIs.</p>
<p>These include a wide selection of combo-box (drop-down) controls &#8211; calculator, file/folder selection, date selection, color selection, multi-elements selection etc.<br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Date selection comb-box" src="https://undocumentedmatlab.com/images/JIDE_DateComboBox.png" title="Date selection combo-box" width="200" /><figcaption class="wp-caption-text">Date selection combo-box</figcaption></figure></center></p>
<p>In addition, a very wide selection of lists, trees and table types is available.<br />
<center><figure style="width: 342px" class="wp-caption aligncenter"><img decoding="async" alt="TreeTable example" src="https://undocumentedmatlab.com/images/treeTable_InteractiveGrouping.jpg" title="TreeTable example" width="342" /><figcaption class="wp-caption-text">TreeTable example</figcaption></figure></center></p>
<p>Also included is a set of specialized editbox controls for accepting IP addresses and credit card numbers:<br />
<center><figure style="width: 350px" class="wp-caption aligncenter"><img decoding="async" alt="IP address entry box" src="https://undocumentedmatlab.com/images/JIDE_IPTextField.png" title="IP address entry box" width="100" /><img decoding="async" alt="credit-card entry box" src="https://undocumentedmatlab.com/images/JIDE_CreditCard_invalid.png" title="credit-card entry box" width="100" /><img decoding="async" alt="credit-card entry box" src="https://undocumentedmatlab.com/images/JIDE_CreditCard_Visa.png" title="credit-card entry box" width="100" /><figcaption class="wp-caption-text">IP address and credit-card entry boxes</figcaption></figure></center></p>
<p>While not explaining all these controls in detail (this could take hundreds of pages), this section does say a few words on each of them, and includes links to online resources for further exploration.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-customization-report">Uitable customization report</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/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/treetable" rel="bookmark" title="treeTable">treeTable </a> <small>A description of a sortable, groupable tree-table control that can be used in Matlab is provided. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-3-basic-customization" rel="bookmark" title="Matlab toolstrip – part 3 (basic customization)">Matlab toolstrip – part 3 (basic customization) </a> <small>Matlab toolstrips can be created and customized in a variety of ways. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitable-customization-report/feed</wfw:commentRss>
			<slash:comments>81</slash:comments>
		
		
			</item>
		<item>
		<title>Uitable sorting</title>
		<link>https://undocumentedmatlab.com/articles/uitable-sorting?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitable-sorting</link>
					<comments>https://undocumentedmatlab.com/articles/uitable-sorting#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 26 Jul 2011 18:00:01 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2391</guid>

					<description><![CDATA[<p>Matlab's uitables can be sortable using simple undocumented features</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-sorting">Uitable sorting</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/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-and-the-event-dispatch-thread-edt" rel="bookmark" title="Matlab and the Event Dispatch Thread (EDT)">Matlab and the Event Dispatch Thread (EDT) </a> <small>The Java Swing Event Dispatch Thread (EDT) is very important for Matlab GUI timings. This article explains the potential pitfalls and their avoidance using undocumented Matlab functionality....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/uitable.html"><i><b>uitable</b></i></a> is probably the most complex basic GUI controls available in Matlab. It displays data in a table within a figure, with settable properties as with any other Matlab Handle-Graphics (HG) control. After many years in which the <i><b>uitable</b></i> was available but <a target="_blank" href="/articles/legend-semi-documented-feature/#Semi-documented">semi-documented</a> and not officially supported in Matlab, it finally became fully documented and supported in R2008a (aka Matlab 7.6). At that time its internal implementation has changed from a MathWorks-developed Java table to a <a target="_blank" href="/articles/tag/JIDE/">JIDE</a>-based Java table (another JIDE-derived table was described <a target="_blank" href="/articles/jide-property-grids/">here</a> last year). Since R2008a, both versions of <i><b>uitable</b></i> are available &#8211; the old version is available by adding the &#8216;v0&#8217; input arg.<br />
Matlab&#8217;s <i><b>uitable</b></i> exposes only a very limited subset of functionalities and properties to the user. Numerous other functionalities are available by accessing the underlying Java table and hidden Matlab properties. Today I will describe a very <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/1880-uitable-can-the-headers-be-made-clickable">common need</a> in GUI tables, that for some unknown reason is missing in Matlab&#8217;s <i><b>uitable</b></i>: Sorting table data columns.<br />
Last week I <a target="_blank" href="/articles/running-vb-code-in-matlab/">explained</a> how we can modify table headers of an ActiveX table control to display sorting icons. In that case, sorting was built-in the control, and the question was just how to display the sorting arrow icon. Unfortunately, Matlab&#8217;s <i><b>uitable</b></i> does not have sorting built-in, although it&#8217;s quite easy to add it, as I shall now show.</p>
<h3 id="Old">Old uitable sorting</h3>
<p>The old <i><b>uitable</b></i> is the default control used until R2007b, or that can be selected with the &#8216;v0&#8217; input arg since R2008a. It was based on an internal MathWorks extension of the standard Java Swing <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/tutorial/uiswing/components/table.html">JTable</a> &#8211; a class called <code>com.mathworks.widgets.spreadsheet.SpreadsheetTable</code>.<br />
Users will normally try to sort columns by clicking the header. This has been a deficiency of JTable for ages. To solve this for the old (pre-R2008a) <i><b>uitable</b></i>, download one of several available JTable sorter classes, or my TableSorter class (available <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14225-java-based-data-table">here</a>).  Add the TableSorter.jar file to your static java classpath (via <code>edit('classpath.txt')</code>) or your dynamic classpath (<code>javaaddpath('TableSorter.jar')</code>).</p>
<pre lang='matlab'>
% Display the uitable and get its underlying Java object handle
[mtable,hcontainer] = uitable('v0', gcf, magic(3), {'A', 'B', 'C'});   % discard the 'v0' in R2007b and earlier
jtable = mtable.getTable;   % or: get(mtable,'table');
% We want to use sorter, not data model...
% Unfortunately, UitablePeer expects DefaultTableModel not TableSorter so we need a modified UitablePeer class
% But UitablePeer is a Matlab class, so use a modified TableSorter & attach it to the Model
if ~isempty(which('TableSorter'))
   % Add TableSorter as TableModel listener
   sorter = TableSorter(jtable.getModel());
   jtable.setModel(sorter);
   sorter.setTableHeader(jtable.getTableHeader());
   % Set the header tooltip (with sorting instructions)
   jtable.getTableHeader.setToolTipText('<html>&nbsp;<b>Click</b> to sort up; <b>Shift-click</b> to sort down<br />&nbsp;...</html>');
else
   % Set the header tooltip (no sorting instructions...)
   jtable.getTableHeader.setToolTipText('<html>&nbsp;<b>Click</b> to select entire column<br />&nbsp;<b>Ctrl-click</b> (or <b>Shift-click</b>) to select multiple columns&nbsp;</html>');
end
</pre>
<p><center><figure style="width: 597px" class="wp-caption aligncenter"><img decoding="async" alt="Sorted uitable - old version" src="https://undocumentedmatlab.com/images/table.png" title="Sorted uitable - old version" width="597" /><figcaption class="wp-caption-text">Sorted <i><b>uitable</b></i> - old version</figcaption></figure></center></p>
<h3 id="New">New uitable sorting</h3>
<p>The new <i><b>uitable</b></i> is based on JIDE&#8217;s <code>com.jidesoft.grid.SortableTable</code> and so has built-in sorting support – all you need to do is to turn it on. First get the underlying Java object using my <a target="_blank" href="/articles/findjobj-find-underlying-java-object/">FindJObj utility</a>:</p>
<pre lang='matlab'>
% Display the uitable and get its underlying Java object handle
mtable = uitable(gcf, 'Data',magic(3), 'ColumnName',{'A', 'B', 'C'});
jscrollpane = findjobj(mtable);
jtable = jscrollpane.getViewport.getView;
% Now turn the JIDE sorting on
jtable.setSortable(true);		% or: set(jtable,'Sortable','on');
jtable.setAutoResort(true);
jtable.setMultiColumnSortable(true);
jtable.setPreserveSelectionsAfterSorting(true);
</pre>
<p>Note: the Matlab <code>mtable</code> handle has a hidden <b>Sortable</b> property, but it has no effect – use the Java property mentioned above instead. I assume that the hidden <b>Sortable</b> property was meant to implement the sorting behavior in R2008a, but MathWorks never got around to actually implement it, and so it remains this way to this day.</p>
<h3 id="Report">A more detailed report</h3>
<p>I have prepared a 45-page PDF report about using and customizing Matlab&#8217;s <i><b>uitable</b></i>, which greatly expands on the above. This report is available for $25 <a target="_blank" rel="nofollow" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&#038;business=altmany@gmail.com&#038;currency_code=USD&#038;amount=25&#038;return=&#038;item_name=Matlab-uitable-report">here</a> (please allow up to 48 hours for email delivery). The report includes the following (more details <a target="_blank" href="/articles/uitable-customization-report/">here</a>):</p>
<ul>
<li>comparison of the old vs. the new <i><b>uitable</b></i> implementations</li>
<li>description of the <i><b>uitable</b></i> properties and callbacks</li>
<li>alternatives to <i><b>uitable</b></i> using a variety of technologies</li>
<li>updating a specific cell&#8217;s value</li>
<li>setting background and foreground colors for a cell or column</li>
<li>using dedicated cell renderer and editor components</li>
<li>HTML processing</li>
<li>setting dynamic cell-specific tooltip</li>
<li>setting dynamic cell-specific drop-down selection options</li>
<li>using a color-selection drop-down for cells</li>
<li>customizing scrollbars</li>
<li>customizing column widths and resizing</li>
<li>customizing selection behavior</li>
<li>data sorting (expansion of today&#8217;s article)</li>
<li>data filtering (similar to Excel&#8217;s data filtering control)</li>
<li>merging table cells</li>
<li>programmatically adding/removing rows</li>
<li>numerous links to online resources</li>
<li>overview of the JIDE grids package, which contains numerous extremely useful GUI controls and components</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-sorting">Uitable sorting</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/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-cell-colors" rel="bookmark" title="Uitable cell colors">Uitable cell colors </a> <small>A few Java-based customizations can transform a plain-looking data table into a lively colored one. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers" rel="bookmark" title="Multi-line uitable column headers">Multi-line uitable column headers </a> <small>Matlab uitables can present long column headers in multiple lines, for improved readability. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-and-the-event-dispatch-thread-edt" rel="bookmark" title="Matlab and the Event Dispatch Thread (EDT)">Matlab and the Event Dispatch Thread (EDT) </a> <small>The Java Swing Event Dispatch Thread (EDT) is very important for Matlab GUI timings. This article explains the potential pitfalls and their avoidance using undocumented Matlab functionality....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitable-sorting/feed</wfw:commentRss>
			<slash:comments>45</slash:comments>
		
		
			</item>
		<item>
		<title>An interesting uitree utility</title>
		<link>https://undocumentedmatlab.com/articles/interesting-uitree-utility?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=interesting-uitree-utility</link>
					<comments>https://undocumentedmatlab.com/articles/interesting-uitree-utility#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Mar 2011 18:00:59 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2218</guid>

					<description><![CDATA[<p>ExploreStruct is a utility that shows how custom uitrees can be integrated in Matlab GUI</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/interesting-uitree-utility">An interesting uitree utility</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-uitree" rel="bookmark" title="Customizing uitree">Customizing uitree </a> <small>This article describes how to customize Matlab GUI tree controls created using the undocumented uitree function...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2" rel="bookmark" title="Customizing uitree nodes &#8211; part 2">Customizing uitree nodes &#8211; part 2 </a> <small>This article shows how Matlab GUI tree nodes can be customized with checkboxes and similar controls...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitree" rel="bookmark" title="uitree">uitree </a> <small>This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component...</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>&#8220;uitree&#8221; is consistently one of the most-popular search terms on this site, together with &#8220;uitable&#8221; and &#8220;uitab&#8221;. I also receive frequent questions about tree components in Matlab.<br />
I already wrote a series of articles on Matlab&#8217;s built-in <a target="_blank" href="/articles/legend-semi-documented-feature/#Semi-documented">semi-documented</a> <i><b>uitree</b></i> (starting <a target="_blank" href="/articles/uitree/">here</a>), and I am on a constant lookout for additional interesting angles on <i><b>uitree</b></i> to post here. Brett Shoelson&#8217;s recent <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2011/03/25/looking-back-2005-in-review/">review</a> of 2005&#8217;s Pick-of-the-Week utilities, provided me with such an opportunity.<br />
One of 2005&#8217;s featured utilities, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/7828-STRUCTURE%20EXPLORER">Structure Explorer</a> by Hassan Lahdili, originally written using Microsoft&#8217;s TreeView ActiveX control, was apparently rewritten using Matlab&#8217;s Java-based <i><b>uitree</b></i>. This enables the utility to run on non-Windows platforms and have a more consistent look-and-feel with Matlab&#8217;s Java-based GUI:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/7828/versions/1/screenshot.JPG"><img loading="lazy" decoding="async" alt="Hassan Lahdili's Structure Explorer (click to enlarge)" src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/7828/versions/1/screenshot.JPG" title="Hassan Lahdili's Structure Explorer (click to enlarge)" width="450" height="325" /></a><figcaption class="wp-caption-text">Hassan Lahdili's Structure Explorer (click to enlarge)</figcaption></figure></center><br />
Hassan&#8217;s ExploreStruct utility, in addition to being useful as-is, provides a very useful learning tool for <i><b>uitree</b></i> integration in Matlab GUI. This utility uses custom icons for different node types, custom callbacks for node expansion (<b>NodeWillExpandCallback</b>) and node selection (<b>NodeSelectedCallback</b>), and tree context (right-click) menu.<br />
Unfortunately, it appears that the ExploreStruct utility has not been updated for compatibility with the latest Matlab releases. This causes numerous warning messages about not using &#8216;v0&#8217; when calling <i><b>uitree</b></i> and <i><b>uitreenode</b></i>. I also had to add a call to <i><b>drawnow</b></i> following the <i><b>uitree</b></i>&#8216;s creation in line #30, otherwise the tree did not appear (<a target="_blank" href="/articles/matlab-and-the-event-dispatch-thread-edt/">due to EDT issues</a>). Also, I had to comment out line #83 (<i>set(root,&#8217;UIContextMenu&#8217;, cmenu);</i>) which caused an error (<i>&#8220;There is no &#8216;UIContextMenu&#8217; property in the &#8216;com.mathworks.hg.peer.UITreeNode&#8217; class&#8221;</i>) &#8211; the tree&#8217;s context-menu actually works even without this line.<br />
Finally, I had to fix line #182 so that the node icons will appear correctly:</p>
<pre lang="matlab">
%pth = [matlabroot, '\work\exp_struct_icons\'];  %old
pth = [fileparts(which(mfilename)) '\exp_struct_icons\'];  %new
</pre>
<p>ExploreStruct is not documented and does not have extensive error-checking that I would like to see in real-world applications. But it is relatively easy to read and understand due to its use of internal functions and meaningful variable names.<br />
Altogether, aside from the minor nuances mentioned above, I believe that readers who are interested in implementing custom tree objects in their Matlab GUI can learn a lot from this utility, and you can easily adapt its code for your own needs (or if you can&#8217;t, I am always <a target="_blank" href="/consulting/">willing to help</a>).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/interesting-uitree-utility">An interesting uitree utility</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-uitree" rel="bookmark" title="Customizing uitree">Customizing uitree </a> <small>This article describes how to customize Matlab GUI tree controls created using the undocumented uitree function...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2" rel="bookmark" title="Customizing uitree nodes &#8211; part 2">Customizing uitree nodes &#8211; part 2 </a> <small>This article shows how Matlab GUI tree nodes can be customized with checkboxes and similar controls...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitree" rel="bookmark" title="uitree">uitree </a> <small>This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component...</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/interesting-uitree-utility/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Hierarchical Systems with UDD</title>
		<link>https://undocumentedmatlab.com/articles/hierarchical-systems-with-udd?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hierarchical-systems-with-udd</link>
					<comments>https://undocumentedmatlab.com/articles/hierarchical-systems-with-udd#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 Mar 2011 18:00:25 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[JMI]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[schema.prop]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2146</guid>

					<description><![CDATA[<p>UDD objects can be grouped in structured hierarchies - this article explains how</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hierarchical-systems-with-udd">Hierarchical Systems with UDD</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/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/introduction-to-udd" rel="bookmark" title="Introduction to UDD">Introduction to UDD </a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I welcome guest blogger <a target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>, who continues his multi-part series about Matlab’s undocumented UDD objects.</i><br />
We have looked at the <a target="_blank" href="/articles/introduction-to-udd/">tools for working with UDD classes</a>, and <a target="_blank" href="/articles/creating-a-simple-udd-class/">created a simple UDD class</a>. Today I shall show how to create a hierarchy of UDD objects.</p>
<h3 id="hierarchy">Creating hierarchical structures with UDD objects</h3>
<p>UDD is the foundation for both Handle Graphics (HG) and Simulink. Both are hierarchical systems. It stands to reason that UDD would offer support for hierarchical structures. It is straightforward to connect UDD objects together into searchable tree structures. All that is necessary is a collection of UDD objects that don&#8217;t have any methods or properties named <code>'connect', 'disconnect', 'up', 'down', 'left', 'right'</code> or <code>'find'</code>.<br />
We illustrate the technique by creating a hierarchy of <code>simple.object</code>s as shown in the following diagram:<br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Sample UDD objects hierarchy" src="https://undocumentedmatlab.com/images/UDD_structure.png" title="Sample UDD objects hierarchy" width="200" height="177" /><figcaption class="wp-caption-text">Sample UDD objects hierarchy</figcaption></figure></center><br />
To begin we create five instances of the <code>simple.object</code> class from the previous article:</p>
<pre lang="matlab">
% Remember that simple.object accepts a name and a value
a = simple.object('a', 1);
b = simple.object('b', 1);
c = simple.object('c', 0);
d = simple.object('d', 1);
e = simple.object('e', 1);
</pre>
<p>To form the structure we use the <i>connect</i> method. We can use either dot notation or the Matlab syntax:</p>
<pre lang="matlab">
% Dot-notation examples:
a.connect(b, 'down');
b.connect(a, 'up');       % alternative to the above
% Matlab notation examples:
connect(a, b, 'down');
connect(b, a, 'up');      % alternative to the above
</pre>
<p>Next, connect node c into our hierarchy. There are several options here: We can use &#8216;down&#8217; to connect a to c. Or we could use &#8216;up&#8217; to connect c to a. Similarly, we can use either &#8216;left&#8217; or &#8216;right&#8217; to connect b and c. Here&#8217;s one of the many possible ways to create our entire hierarchy:</p>
<pre lang="matlab">
b.connect(a, 'up');
c.connect(b, 'left');
d.connect(b, 'up');
e.connect(d, 'left');
</pre>
<h3 id="inspecting">Inspecting UDD hierarchy structures</h3>
<p>We now have our structure and each object knows its connection to other objects. For example, we can inspect b&#8217;s connections as follows:</p>
<pre lang="matlab">
>> b.up
ans =
  Name: a
 Value: 1.000000
>> b.right
ans =
  Name: c
 Value: 0.000000
>> b.down
ans =
  Name: d
 Value: 1.000000
</pre>
<p>We can search our structure by using an undocumented form of the built-in <i><b>find</b></i> command. When used with connected UDD structures, <i><b>find</b></i> can be used in the following form:</p>
<pre lang="matlab">objectArray = find(startingNode, 'property', 'value', ...)</pre>
<p>To search from the top of our hierarchy for objects of type <code>simple.object</code> we would use:</p>
<pre lang="matlab">
>> find(a, '-isa', 'simple.object')
ans =
        simple.object: 5-by-1    % a, b, c, d, e
</pre>
<p>Which returns all the objects in our structure, since all of them are <code>simple.object</code>s. If we repeat that command starting at b we would get:</p>
<pre lang="matlab">
>> find(b, '-isa', 'simple.object')
ans =
	simple.object: 3-by-1    % b, d, e
</pre>
<p><i><b>find</b></i> searches the structure downward from the current node. Like many Matlab functions, <i><b>find</b></i> can be used with multiple property value pairs, so if we want to find <code>simple.object</code> objects in our structure with <b>Value</b> property =0, we would use the command:</p>
<pre lang="matlab">
>> find(a, '-isa', 'simple.object', 'Value', 0)
ans =
  Name: c
 Value: 0.000000
</pre>
<h3 id="visualizing">Visualizing a UDD hierarchy</h3>
<p>Hierarchical structures are also known as tree structures. Matlab has an undocumented function for visualizing and working with trees namely <i><b>uitree</b></i>. Yair has described <i><b>uitree</b></i> in a <a target="_blank" href="/articles/uitree/">series of articles</a>. Rather than following the techniques in shown in Yair&#8217;s articles, we are going to use a different method that will allow us to introduce the following important techniques for working with UDD objects:</p>
<ul>
<li>Subclassing, building your class on the foundation of a parent class</li>
<li>Overloading properties and methods of the superclass</li>
<li>Using meta-properties <b>GetfFunction</b> and <b>SetFunction</b></li>
</ul>
<p>Because the steps shown below will subclass an HG class, they will modify our <code>simple.object</code> class and probably make it unsuitable for general use. Yair has shown that <i><b>uitree</b></i> is ready made for displaying HG trees and we saw above that HG is a UDD system. We will use the technique from <code>uitools.uibuttongroup</code> to make our <code>simple.object</code> class a subclass of the HG class <code>hg.uipanel</code>. Modify the class definition file as follows:</p>
<pre lang="matlab">
% class definition
superPackage = findpackage('hg');
superClass = findclass(superPackage, 'uipanel');
simpleClass = schema.class(simplePackage, 'object',superClass);
</pre>
<p>Now we can either issue the <i><b>clear classes</b></i> command or restart Matlab and then recreate our structure. The first thing that you will notice is that when we create the first <code>simple.object</code> that a figure is also created. This is expected and is the reason that this technique is not useful in general. We will however use this figure to display our structure with the following commands:</p>
<pre lang="matlab">
t = uitree('v0', 'root', a);  drawnow;
t.expand(t.getRoot);  drawnow;
t.expand(t.getRoot.getFirstChild);
</pre>
<p><center><figure style="width: 441px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Simple structure presented in a Matlab uitree" src="https://undocumentedmatlab.com/images/UDD_uitree_1.png" title="Simple structure presented in a Matlab uitree" width="441" height="189" /><figcaption class="wp-caption-text">Simple structure presented in a Matlab <i><b>uitree</b></i></figcaption></figure></center><br />
The label on each of our objects is &#8216;uipanel&#8217; and this is probably not what we want. If we inspect our object or its <code>hg.uipanel</code> super-class (note: this would be a great time to use Yair&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object"><i><b>uiinspect</b></i> utility</a>), we can see there is a <b>Type</b> property that has a value of &#8216;uipanel&#8217;. Unfortunately this property is read-only, so we cannot change it. We can however overload it by placing a <i><b>schema.prop</b></i> in our class definition named <b>Type</b>. This will allow us to overload or replace the parent&#8217;s <b>Type</b> property with our own definition:</p>
<pre lang="matlab">
p = schema.prop(simpleClass, 'Type', 'string');
p.FactoryValue = 'simple.object';
</pre>
<p>Once again, issue the <i><b>clear classes</b></i> command or restart Matlab, then recreate our structure. Our tree now has each node labeled with the &#8216;simple.object&#8217; label:<br />
<center><figure style="width: 441px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Corrected node names for our UDD structure" src="https://undocumentedmatlab.com/images/UDD_uitree_2.png" title="Corrected node names for our UDD structure" width="441" height="189" /><figcaption class="wp-caption-text">Corrected node names for our UDD structure</figcaption></figure></center><br />
This is a little more descriptive but what would really be nice is if we could label each node with the value of the <b>Name</b> property. As luck would have it, we can do just that. When we add a property to a UDD class we are adding an object of type <code>schema.prop</code>. So our properties have their own properties and methods (so-called <i>meta-data</i>). We are going to set the <b>GetFunction</b> property of our <b>Type</b> property. <b>GetFunction</b> holds a handle of the function to be called whenever the property is accessed:</p>
<pre lang="matlab">
p = schema.prop(simpleClass, 'Type', 'string');
p.GetFunction = @getType;
</pre>
<p>The prototype for the function that <b>GetFunction</b> references has three inputs and one output: The inputs are the handle of the object possessing the property, the value of that property, and the property object. The output is the value that will be supplied when the property is accessed. So our <b>GetFunction</b> can be written to supply the value of the <b>Name</b> property whenever the <b>Type</b> property value is being read:</p>
<pre lang="matlab">
function propVal = getType(self, value, prop)
   propVal = self.Name;
end
</pre>
<p>Alternately, as a single one-liner in the schema definition file:</p>
<pre lang="matlab">p.GetFunction = @(self,value,prop) self.Name;</pre>
<p>Similarly, there is a corresponding <b>SetFunction</b> that enables us to intercept changes to a property&#8217;s value and possibly disallow invalid values.<br />
With these changes when we recreate our <i><b>uitree</b></i> we obtain:<br />
<center><figure style="width: 441px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Overloaded property GetFunction" src="https://undocumentedmatlab.com/images/UDD_uitree_3.png" title="Overloaded property GetFunction" width="441" height="189" /><figcaption class="wp-caption-text">Overloaded property <b>GetFunction</b></figcaption></figure></center></p>
<h3 id="java">A Java class for UDD trees</h3>
<p>We will have more to say about the relationship between UDD and Java in a future article. For now we simply note that the <code>com.mathworks.jmi.bean.UDDObjectTreeModel</code> class in the <a target="_blank" href="/articles/jmi-java-to-matlab-interface/">JMI package</a> provides some UDD tree navigation helper functions. Methods include <i>getChild, getChildCount, getIndexOfChild</i> and <i>getPathToRoot</i>. The <code>UDDObjectTreeModel</code> constructor requires one argument, an instance of your UDD tree root node:</p>
<pre lang="matlab">
% Create a UDD tree-model instance
>> uddTreeModel = com.mathworks.jmi.bean.UDDObjectTreeModel(a);
% Get index of child e and its parent b:
>> childIndex = uddTreeModel.getIndexOfChild(b, e)
childIndex =
     1
% Get the root's first child (#0):
>> child0 = uddTreeModel.getChild(a, 0)
child0 =
  Name: b
 Value: 1.000000
% Get the path from node e to the root:
>> path2root = uddTreeModel.getPathToRoot(e)
path2root =
com.mathworks.jmi.bean.UDDObject[]:
    [simple_objectBeanAdapter2]      % <= a
    [simple_objectBeanAdapter2]      % <= b
    [simple_objectBeanAdapter2]      % <= e
>> path2root(3)
ans =
  Name: e
 Value: 1.000000
</pre>
<p>We touched on a few of the things that you can do by modifying the properties of a <code>schema.prop</code> in this article. In the following article we will take a more detailed look at this essential class.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hierarchical-systems-with-udd">Hierarchical Systems with UDD</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/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/introduction-to-udd" rel="bookmark" title="Introduction to UDD">Introduction to UDD </a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/hierarchical-systems-with-udd/feed</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>uisplittool &#038; uitogglesplittool callbacks</title>
		<link>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uisplittool-uitogglesplittool-callbacks</link>
					<comments>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 15 Dec 2010 18:00:35 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[uitools]]></category>
		<category><![CDATA[uiundo]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1999</guid>

					<description><![CDATA[<p>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks">uisplittool &amp; uitogglesplittool callbacks</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/uisplittool-uitogglesplittool" rel="bookmark" title="uisplittool &amp; uitogglesplittool">uisplittool &amp; uitogglesplittool </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan" rel="bookmark" title="Enabling user callbacks during zoom/pan">Enabling user callbacks during zoom/pan </a> <small>Matlab zoom, pan and rotate3d modes hijack the user's figure callbacks, but this can be overridden. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week, I presented the undocumented <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> functions and showed how they can be added to a Matlab figure toolbar. Today I wish to conclude this topic by explaining how these controls can be customized with user-defined callbacks and pop-up menus.</p>
<h3 id="Callbacks">Callback functionality</h3>
<p>Both <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> have a <strong>Callback</strong> property, in addition to the standard <strong>ClickedCallback</strong> property that is available in <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s.<br />
The standard <strong>ClickedCallback</strong> is invoked when the main button is clicked, while <strong>Callback</strong> is invoked when the narrow arrow button is clicked. <i><b>uitogglesplittool</b></i>, like <i><b>uitoggletool</b></i>, also has settable <strong>OnCallback</strong> and <strong>OffCallback</strong> callback properties.<br />
The accepted convention is that <strong>ClickedCallback</strong> should invoke the default control action (in our case, an Undo/Redo of the topmost <a target="_blank" href="/articles/uiundo-matlab-undocumented-undo-redo-manager/">uiundo action stack</a>), while <strong>Callback</strong> should display a drop-down of selectable actions.<br />
While this can be done programmatically using the <strong>Callback</strong> property, this functionality is already pre-built into <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> for our benefit. To access it, we need to get the control&#8217;s underlying Java component.<br />
Accessing the underlying Java component is normally done using the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/">findjobj utility</a>, but in this case we have a shortcut: the control handle&#8217;s hidden <strong>JavaContainer</strong> property that holds the underlying <i>com.mathworks.hg.peer.SplitButtonPeer</i> (or <i>.ToggleSplitButtonPeer</i>) Java reference handle. This Java object&#8217;s <strong>MenuComponent</strong> property returns a reference to the control&#8217;s drop-down sub-component (which is a <i>com.mathworks.mwswing.MJPopupMenu</i> object):</p>
<pre lang="matlab">
>> jUndo = get(hUndo,'JavaContainer')
jUndo =
com.mathworks.hg.peer.SplitButtonPeer@f09ad5
>> jMenu = get(jUndo,'MenuComponent')  % or: =jUndo.getMenuComponent
jMenu =
com.mathworks.mwswing.MJPopupMenu[Dropdown Picker ButtonMenu,...]
</pre>
<p>Let&#8217;s add a few simple textual options:</p>
<pre lang="matlab">
jOption1 = jMenu.add('Option #1');
jOption1 = jMenu.add('Option #2');
set(jOption1, 'ActionPerformedCallback', 'disp(''option #1'')');
set(jOption2, 'ActionPerformedCallback', {@myCallbackFcn, extraData});
</pre>
<p><center><figure style="width: 310px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="setting uisplittool &amp; uitogglesplittool popup-menus" src="https://undocumentedmatlab.com/images/uisplittool3.png" title="setting uisplittool &amp; uitogglesplittool popup-menus" width="99" height="72" /><figcaption class="wp-caption-text">setting <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> popup-menus</figcaption></figure></center><br />
Popup-menus are described in more detail elsewhere (and in future articles). In the past I have already explained how icons and HTML markup can be added to menu items. Sub-menus can also be added.</p>
<h3 id="Example">A complete example</h3>
<p>Let&#8217;s now use this information, together with last year&#8217;s <a target="_blank" href="/articles/tag/uiundo/">set of articles</a> about Matlab&#8217;s undocumented <i><b>uiundo</b></i> functionality, to generate a complete and more realistic example, of undo/redo toolbar buttons.<br />
Undo and redo are actions that are particularly suited for <i><b>uisplittool</b></i>, since its main button enables us to easily undo/redo the latest action (like a simple toolbar button, by clicking the main <i><b>uisplittool</b></i> button) as well as select items from the actions drop-down (like a combo-box, by clicking the attached arrow button) – all this using a single component.</p>
<pre lang="matlab">
% Display our GUI
hEditbox = uicontrol('style','edit', 'position',[20,60,40,40]);
set(hEditbox, 'Enable','off', 'string','0');
hSlider = uicontrol('style','slider','userdata',hEditbox);
set(hSlider,'Callback',@test_uiundo);
% Display the figure toolbar that was hidden by the uicontrol function
set(gcf,'Toolbar','figure');
% Add the Undo/Redo buttons
hToolbar = findall(gcf,'tag','FigureToolBar');
hUndo = uisplittool('parent',hToolbar);
hRedo = uitogglesplittool('parent',hToolbar);
% Load the Redo icon
icon = fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif');
[cdata,map] = imread(icon);
% Convert white pixels into a transparent background
map(find(map(:,1)+map(:,2)+map(:,3)==3)) = NaN;
% Convert into 3D RGB-space
cdataRedo = ind2rgb(cdata,map);
cdataUndo = cdataRedo(:,[16:-1:1],:);
% Add the icon (and its mirror image = undo) to latest toolbar
set(hUndo, 'cdata',cdataUndo, 'tooltip','undo','Separator','on', ...
           'ClickedCallback','uiundo(gcbf,''execUndo'')');
set(hRedo, 'cdata',cdataRedo, 'tooltip','redo', ...
           'ClickedCallback','uiundo(gcbf,''execRedo'')');
% Re-arrange the Undo/Redo buttons
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jButtons = jToolbar.getComponents;
for buttonIdx = length(jButtons)-3 : -1 : 7  % end-to-front
   jToolbar.setComponentZOrder(jButtons(buttonIdx), buttonIdx+1);
end
jToolbar.setComponentZOrder(jButtons(end-2), 5);    % Separator
jToolbar.setComponentZOrder(jButtons(end-1), 6);    % Undo
jToolbar.setComponentZOrder(jButtons(end), 7);      % Redo
jToolbar.revalidate;
% Retrieve redo/undo object
undoObj = getappdata(gcf,'uitools_FigureToolManager');
if isempty(undoObj)
   undoObj = uitools.FigureToolManager(gcf);
   setappdata(gcf,'uitools_FigureToolManager',undoObj);
end
% Populate Undo actions drop-down list
jUndo = get(hUndo,'JavaContainer');
jMenu = get(jUndo,'MenuComponent');
undoActions = get(undoObj.CommandManager.UndoStack,'Name');
jMenu.removeAll;
for actionIdx = length(undoActions) : -1 : 1    % end-to-front
    jActionItem = jMenu.add(undoActions(actionIdx));
    set(jActionItem, 'ActionPerformedCallback', @myUndoCallbackFcn);
end
jToolbar.revalidate;
% Drop-down callback function
function myUndoCallbackFcn(jActionItem,hEvent)
    % user processing needs to be placed here
end  % myUndoCallbackFcn
</pre>
<p><center><figure style="width: 395px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="undo/redo buttons implemented using uisplittool" src="https://undocumentedmatlab.com/images/uisplittool4b.png" title="undo/redo buttons implemented using uisplittool" width="395" height="257" /><figcaption class="wp-caption-text">undo/redo buttons implemented using <i><b>uisplittool</b></i></figcaption></figure></center><br />
In a real-world application, the code-segment above that populated the drop-down list would be placed within the slider&#8217;s <em>test_uiundo()</em> callback function, and we would set a similar drop-down for the hRedu button. In addition, we would dynamically modify the button tooltips. As a final customization, we could modify the figure&#8217;s main menu. Menu customization will be discussed in a future separate set of articles.<br />
Have you used <i><b>uisplittool</b></i> or <i><b>uitogglesplittool</b></i> in your GUI? If so, please tell us what use you have made of them, in a comment <a href="/articles/uisplittool-uitogglesplittool-callbacks/#respond">below</a>. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks">uisplittool &amp; uitogglesplittool callbacks</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/uisplittool-uitogglesplittool" rel="bookmark" title="uisplittool &amp; uitogglesplittool">uisplittool &amp; uitogglesplittool </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan" rel="bookmark" title="Enabling user callbacks during zoom/pan">Enabling user callbacks during zoom/pan </a> <small>Matlab zoom, pan and rotate3d modes hijack the user's figure callbacks, but this can be overridden. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool-callbacks/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>uisplittool &#038; uitogglesplittool</title>
		<link>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uisplittool-uitogglesplittool</link>
					<comments>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 09 Dec 2010 00:06:33 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[uitools]]></category>
		<category><![CDATA[uiundo]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1994</guid>

					<description><![CDATA[<p>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool">uisplittool &amp; uitogglesplittool</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/uisplittool-uitogglesplittool-callbacks" rel="bookmark" title="uisplittool &amp; uitogglesplittool callbacks">uisplittool &amp; uitogglesplittool callbacks </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/toolbar-button-labels" rel="bookmark" title="Toolbar button labels">Toolbar button labels </a> <small>GUI toolbar button labels can easily be set and customized using underlying Java components. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager" rel="bookmark" title="uiundo &#8211; Matlab&#039;s undocumented undo/redo manager">uiundo &#8211; Matlab&#039;s undocumented undo/redo manager </a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Matlab 7.6 (R2008a) and onward contain a reference to <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> in the javacomponent.m and %matlabroot%/bin/registry/hg.xml files. These are reported as built-in functions by the <i><b>which</b></i> function, although they have no corresponding m-file as other similar built-in functions (note the double &#8216;t&#8217;, as in <i>split-tool</i>):</p>
<pre lang="matlab">
>> which uisplittool
built-in (C:\Matlab\R2010b\toolbox\matlab\uitools\uisplittool)
</pre>
<p>These uitools are entirely undocumented, even today (R2010b). They puzzled me for a very long time. An acute reader (Jeremy Raymonds) suggested they are related to toolbars, like other uitools such as the <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>. This turned out to be the missing clue that unveiled these useful tools:</p>
<h3 id="Intro">So what are <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i>?</h3>
<p>Both <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> are basic Handle-Graphics building blocks used in Matlab toolbars, similarly to the well-documented <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>.<br />
<i><b>uisplittool</b></i> presents a simple drop-down, whereas <i><b>uitogglesplittool</b></i> presents a drop-down that is also selectable.<br />
The Publish and Run controls on the Matlab Editor&#8217;s toolbar are examples of <i><b>uisplittool</b></i>, and so are the Brush / Select-Data control on the figure toolbar, and the plot-selection drop-down on the Matlab Desktop&#8217;s Workspace toolbar:<br />
<center><figure style="width: 361px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uisplittool in action in the Matlab Desktop" src="https://undocumentedmatlab.com/images/uisplittool.png" title="uisplittool in action in the Matlab Desktop" width="361" height="221" /><figcaption class="wp-caption-text"><i><b>uisplittool</b></i> in action in the Matlab Desktop</figcaption></figure></center></p>
<h3 id="Appearance">Adding <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar</h3>
<p>Adding a <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar is done in a similar manner to adding <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s:</p>
<pre lang="matlab">
hToolbar = findall(gcf,'tag','FigureToolBar');
hUndo=uisplittool('parent',hToolbar);       % uisplittool
hRedo=uitogglesplittool('parent',hToolbar); % uitogglesplittool
</pre>
<p>Like <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>, <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> also have unique <strong>Type</strong> property values, &#8216;uisplittool&#8217; and &#8216;uitogglesplittool&#8217; respectively. The handles can also be tested using the built-in <i><b>isa</b></i> function:</p>
<pre lang="matlab">
>> isa(handle(hUndo),'uisplittool')   % or: 'uitogglesplittool'
ans =
     1
>> class(handle(hUndo))
ans =
uisplittool
</pre>
<p>Just as with <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s, the new buttons have an empty button-face appearance, until we fix their <strong>CData</strong>, <strong>Tooltip</strong> and similar settable properties:</p>
<pre lang="matlab">
% Load the Redo icon
icon = fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif');
[cdata,map] = imread(icon);
% Convert white pixels into a transparent background
map(find(map(:,1)+map(:,2)+map(:,3)==3)) = NaN;
% Convert into 3D RGB-space
cdataRedo = ind2rgb(cdata,map);
cdataUndo = cdataRedo(:,[16:-1:1],:);
% Add the icon (and its mirror image = undo) to latest toolbar
set(hUndo, 'cdata',cdataUndo, 'tooltip','undo','Separator','on', ...
           'ClickedCallback','uiundo(gcbf,''execUndo'')');
set(hRedo, 'cdata',cdataRedo, 'tooltip','redo', ...
           'ClickedCallback','uiundo(gcbf,''execRedo'')');
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="User-created uisplittool &amp; uitogglesplittool toolbar buttons" src="https://undocumentedmatlab.com/images/uisplittool2b2.png" title="User-created uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="107" /><figcaption class="wp-caption-text">User-created <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons</figcaption></figure></center><br />
Note that the controls can be created with these properties in a single command:</p>
<pre lang="matlab">hUndo = uisplittool('parent',hToolbar, 'cdata',cdataRedo, ...);</pre>
<h3 id="Arranging">Re-arranging the toolbar controls placement</h3>
<p>Let us now re-arrange our toolbar buttons. Unfortunately, a bug causes <i><b>uisplittool</b></i>s and <i><b>uitogglesplittool</b></i>s to always be placed flush-left when the toolbar&#8217;s children are re-arranged (anyone at TMW reading this in time for the R2011a bug-parade selection?).<br />
So, we can&#8217;t re-arrange the buttons at the HG-children level. Luckily, we can re-arrange directly at the Java level (note that until now, the entire discussion of <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> was purely Matlab-based):</p>
<pre lang="matlab">
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
jButtons = jToolbar.getComponents;
for buttonId = length(jButtons)-3 : -1 : 7  % end-to-front
   jToolbar.setComponentZOrder(jButtons(buttonId), buttonId+1);
end
jToolbar.setComponentZOrder(jButtons(end-2), 5);   % Separator
jToolbar.setComponentZOrder(jButtons(end-1), 6);   % Undo
jToolbar.setComponentZOrder(jButtons(end), 7);     % Redo
jToolbar.revalidate;
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" src="https://undocumentedmatlab.com/images/uisplittool2c2.png" title="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="106" /><figcaption class="wp-caption-text">Re-arranged <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons<br />(not as simple as it may sound)</figcaption></figure></center><br />
Next week, I will combine the information in this article, with <a target="_blank" href="/articles/tag/uiundo/">last year&#8217;s articles</a> about <i><b>uiundo</b></i>, and show how we can create a dynamic figure toolbar drop-down of undo/redo events. Here is a preview to whet your appetite:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="undo/redo buttons implemented using uisplittool" src="https://undocumentedmatlab.com/images/uisplittool4.png" title="undo/redo buttons implemented using uisplittool" width="450" height="226" /><figcaption class="wp-caption-text">undo/redo buttons implemented using <i><b>uisplittool</b></i></figcaption></figure></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool">uisplittool &amp; uitogglesplittool</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/uisplittool-uitogglesplittool-callbacks" rel="bookmark" title="uisplittool &amp; uitogglesplittool callbacks">uisplittool &amp; uitogglesplittool callbacks </a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/toolbar-button-labels" rel="bookmark" title="Toolbar button labels">Toolbar button labels </a> <small>GUI toolbar button labels can easily be set and customized using underlying Java components. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiundo-matlab-undocumented-undo-redo-manager" rel="bookmark" title="uiundo &#8211; Matlab&#039;s undocumented undo/redo manager">uiundo &#8211; Matlab&#039;s undocumented undo/redo manager </a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uisplittool-uitogglesplittool/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Uitab customizations</title>
		<link>https://undocumentedmatlab.com/articles/uitab-customizations?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitab-customizations</link>
					<comments>https://undocumentedmatlab.com/articles/uitab-customizations#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 17 Nov 2010 18:00:16 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1959</guid>

					<description><![CDATA[<p>This article shows several customizations that can be done to Matlab's undocumented tab-panels functionality</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitab-customizations">Uitab 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/uitab-colors-icons-images" rel="bookmark" title="Uitab colors, icons and images">Uitab colors, icons and images </a> <small>Matlab's semi-documented tab panels can be customized using some undocumented hacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="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/uigetfile-uiputfile-customizations" rel="bookmark" title="uigetfile/uiputfile customizations">uigetfile/uiputfile customizations </a> <small>A file-selector dialog window that includes an integrated preview panel is shown and explained. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>This article concludes my planned series on Matlab&#8217;s built-in semi-documented tab-panel functionality. In previous article I have shown how Matlab&#8217;s <i><b>uitab</b></i> and <i><b>uitabgroup</b></i> functions can be used to <a target="_blank" href="/articles/tab-panels-uitab-and-relatives/">present tabbed contents</a>, and how <a target="_blank" href="/articles/uitab-colors-icons-images/">icon images can be attached to tabs</a> using their undocumented underlying Java component. Today I will show other customizations that can be done to tabs.</p>
<h3 id="Disabling">Disabling tabs</h3>
<p>Our first customization is to disable particular tabs. We start with a basic tab group, and get the underlying Java component:</p>
<pre lang="matlab">
% Prevent an annoying warning msg
warning off MATLAB:uitabgroup:OldVersion
% Prepare a tab-group consisting of two tabs
hTabGroup = uitabgroup; drawnow;
tab1 = uitab(hTabGroup, 'title','Panel 1');
a = axes('parent', tab1); surf(peaks);
tab2 = uitab(hTabGroup, 'title','Panel 2');
uicontrol(tab2, 'String','Close', 'Callback','close(gcbf)');
% Get the underlying Java reference (use hidden property)
jTabGroup = getappdata(handle(hTabGroup),'JTabbedPane');
</pre>
<p>Remember that Java uses 0-based indexing so tab #1 is actually the second tab. Let&#8217;s disable it by using the Java object&#8217;s <i>setEnabledAt()</i> method:</p>
<pre lang="matlab">
jTabGroup.setEnabledAt(1,false);  % disable only tab #1 (=second tab)
jTabGroup.setEnabled(false);  % disable all tabs
jTabGroup.setEnabled(true);  % re-enable all tabs (except tab #1)
</pre>
<p><center><figure style="width: 374px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="A disabled tab" src="https://undocumentedmatlab.com/images/uitabgroup9_disabled.png" title="A disabled tab" width="374" height="268" /><figcaption class="wp-caption-text">A disabled tab</figcaption></figure></center><br />
Note that setting the property value for a specific tab overrides the value set for ALL tabs, despite the fact that <i>setEnabled</i> is called after <i>setEnabledAt</i>.</p>
<h3 id="LNF">Look-and-Feel</h3>
<p>Unlike some other controls, tabs have distinctly different appearances in different <a target="_blank" href="/articles/modifying-matlab-look-and-feel/">Look &#038; Feels</a>. Take a look at Plastic3DLookAndFeel, NimbusLookAndFeel and MetalLookAndFeel for tab panels that look distinctly different and more stylish than the WindowsLookAndFeel shown above.<br />
<center><br />
<figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="WindowsLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_windows_small.png" title="WindowsLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">WindowsLookAndFeel</figcaption></figure> <figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="WindowsClassicLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_win_classic_small.png" title="WindowsClassicLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">WindowsClassicLookAndFeel</figcaption></figure><br />
<figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Plastic3DLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_plastic3D_small.png" title="Plastic3DLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">Plastic3DLookAndFeel</figcaption></figure> <figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MotifLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_motif_small.png" title="MotifLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">MotifLookAndFeel</figcaption></figure><br />
<figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MetalLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_metal_small.png" title="MetalLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">MetalLookAndFeel</figcaption></figure> <figure style="width: 160px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="NimbusLookAndFeel" src="https://undocumentedmatlab.com/images/uitabgroup7_lnf_nimbus_small.png" title="NimbusLookAndFeel" width="145" height="80" /><figcaption class="wp-caption-text">NimbusLookAndFeel</figcaption></figure><br />
</center></p>
<h3 id="Other">Other customizations</h3>
<p>There are other things we can customize, such as setting mnemonics (keyboard shortcuts), etc. – refer to the <a target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTabbedPane.html">official documentation</a> or any good textbook about Java Swing.<br />
Tab callbacks are the same as the standard <a target="_blank" href="/articles/uicontrol-callbacks/">Swing components callbacks</a>, except for <b>StateChangedCallback</b>, which is automatically linked to the internal function that synchronizes between the Java tab group and the Matlab uicontainers (in other words: it&#8217;s not a good idea to mess with it…).<br />
Some jTabGroup functions that work well with standard JTabbedPane fail with <i><b>uitabgroup</b></i>: For example, jTabGroup.setIconAt or setTabLayoutPolicy.  I am unsure of the reason for this. Other limitations with <i><b>uitabgroup</b></i> are a reported <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/158711">problem when compiling any GUI that includes it</a>; a reported <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/156065#392032">bug when reordering tabs</a>; a reported <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/235274#597793">problem rendering some graphic object properties (e.g., clipping)</a>; and a reported <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/130100">problem in displaying tabs containing ActiveX</a> or <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/110949">Java objects</a> (plus <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/162430">suggested solutions</a>). Interested readers can fix all these issues by modifying the m-files in the folders %matlabroot%/toolbox/matlab/@uitools/@uitabgroup and /@uitools/@uitab. At least some of these problems are fixed as of R2010a.<br />
Readers might also be interested in the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/20218-yet-another-layout-manager"><i>Yet Another Layout Manager</i> utility</a>. This utility directly uses Swing&#8217;s JTabbedPane object to implement tab panels, essentially mimicking the built-in <i><b>uitab</b></i>/<i><b>uitabgroup</b></i> functions.<br />
This concludes my series on Matlab&#8217;s <i><b>uitab</b></i>. Any other specific customizations you are interested in? Any nice variation of your own? Please do share your thoughts in a <a target="_blank" href="/articles/uitab-customizations/#respond">comment</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitab-customizations">Uitab 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/uitab-colors-icons-images" rel="bookmark" title="Uitab colors, icons and images">Uitab colors, icons and images </a> <small>Matlab's semi-documented tab panels can be customized using some undocumented hacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="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/uigetfile-uiputfile-customizations" rel="bookmark" title="uigetfile/uiputfile customizations">uigetfile/uiputfile customizations </a> <small>A file-selector dialog window that includes an integrated preview panel is shown and explained. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitab-customizations/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Uitab colors, icons and images</title>
		<link>https://undocumentedmatlab.com/articles/uitab-colors-icons-images?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitab-colors-icons-images</link>
					<comments>https://undocumentedmatlab.com/articles/uitab-colors-icons-images#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 Nov 2010 18:00:01 +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[Semi-documented function]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1955</guid>

					<description><![CDATA[<p>Matlab's semi-documented tab panels can be customized using some undocumented hacks</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitab-colors-icons-images">Uitab colors, icons and images</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/uitab-customizations" rel="bookmark" title="Uitab customizations">Uitab customizations </a> <small>This article shows several customizations that can be done to Matlab's undocumented tab-panels functionality...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-system-tray-icons" rel="bookmark" title="Setting system tray icons">Setting system tray icons </a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few months ago I published a post about <a target="_blank" href="/articles/tab-panels-uitab-and-relatives/">Matlab&#8217;s semi-documented tab-panel functionality</a>, where I promised a follow-up article on tab customizations. A reader of this blog <a target="_blank" href="/articles/customizing-uicontrol-border/#comment-21714">asked a related question</a> earlier today, so I decided it&#8217;s about time I fulfilled this promise.<br />
As with most Matlab controls, the underlying Java component enables far greater customization than possible using plain Matlab. Today I will show three specific customizations. We start with a basic tab group, and get the underlying Java component:</p>
<pre lang="matlab">
% Prevent an annoying warning msg
warning off MATLAB:uitabgroup:OldVersion
% Prepare a tab-group consisting of two tabs
hTabGroup = uitabgroup; drawnow;
tab1 = uitab(hTabGroup, 'title','Panel 1');
a = axes('parent', tab1); surf(peaks);
tab2 = uitab(hTabGroup, 'title','Panel 2');
uicontrol(tab2, 'String','Close', 'Callback','close(gcbf)');
% Get the underlying Java reference (use hidden property)
jTabGroup = getappdata(handle(hTabGroup),'JTabbedPane');
</pre>
<h3 id="Colors">Foreground &#038; background tab colors</h3>
<p>We can set the tab font color using <i>setForeground()</i> and <i>setForegroundAt()</i>, or via HTML. Note that <i>setForegroundAt()</i> overrides anything set by <i>setForeground()</i>. Also remember that Java uses 0-based indexing so tab #1 is actually the second tab:</p>
<pre lang="matlab">
% Equivalent manners to set a red tab foreground:
jTabGroup.setForegroundAt(1,java.awt.Color(1.0,0,0)); % tab #1
jTabGroup.setTitleAt(1,'<html><font color="red"><i>Panel 2');
jTabGroup.setForeground(java.awt.Color.red);
</pre>
<p>Unfortunately, the corresponding <i>setBackgroundAt(tabIndex,color)</i> method has no visible effect, and the Matlab-extended tabs keep their white/gray backgrounds. A similar attempt to modify the tab&#8217;s <b>BackgroundColor</b> property fails, since Matlab made this property unmodifiable (=&#8217;none&#8217;).  A simple solution is to use a <a target="_blank" rel="nofollow" href="http://www.w3schools.com/css/css_background.asp">CSS background</a>:</p>
<pre lang="matlab">
% Equivalent manners to set a yellow tab background:
jTabGroup.setTitleAt(0,'<html><div style="background:#ffff00;">Panel 1');
jTabGroup.setTitleAt(0,'<html><div style="background:yellow;">Panel 1');
</pre>
<p><center><figure style="width: 340px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uitabgroup with non-default forground and background tab colors and fonts" src="https://undocumentedmatlab.com/images/uitabgroup5_bgcolor.png" title="uitabgroup with non-default forground and background tab colors and fonts" width="340" height="265" /><figcaption class="wp-caption-text"><i><b>uitabgroup</b></i> with non-default forground and background tab colors and fonts</figcaption></figure></center><br />
We can set the foreground text color using the <a target="_blank" rel="nofollow" href="http://www.w3schools.com/css/css_colors.asp">CSS <i>color</i> directive</a>. Similarly, we can also set a background gradient image for the tabs, using the CSS <i>background-image</i> directive. Which leads us to our next customization:</p>
<h3 id="Icons">Icon images</h3>
<p>Icons and sub-components can be added to the tabs. Unfortunately, for some reason that I do not fully understand, jTabGroup.<i>setIconAt()</i> has no apparent effect. The solution is to set our own custom control as the requested tab, and add our icon (or other customizations) to it. Here is a simple example:</p>
<pre lang="matlab">
% Add an icon to tab #1 (=second tab)
icon = javax.swing.ImageIcon('C:\Yair\save.gif');
jLabel = javax.swing.JLabel('Tab #2');
jLabel.setIcon(icon);
jTabGroup.setTabComponentAt(1,jLabel);	% Tab #1 = second tab
% Note: icon is automatically grayed when label is disabled
jLabel.setEnabled(false);
jTabGroup.setEnabledAt(1,false);  % disable only tab #1
</pre>
<p><center><figure style="width: 292px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="tab with a custom icon (enabled)" src="https://undocumentedmatlab.com/images/uitabgroup6_icon.png" title="tab with a custom icon (enabled)" width="292" height="159" /><br /><img loading="lazy" decoding="async" alt="tab with a custom icon (enabled)" src="https://undocumentedmatlab.com/images/uitabgroup6_icon2.png" title="tab with a custom icon (disabled)" width="292" height="159" /><figcaption class="wp-caption-text">tab with a custom icon (enabled & disabled)</figcaption></figure></center></p>
<h3 id="Buttons">Close buttons</h3>
<p>Now let&#8217;s try a more complex example, of adding a close (&#8216;x&#8217;) button to one of the tabs. Generalizing this code snippet is left as an exercise to the reader:</p>
<pre lang="matlab">
% First let's load the close icon
jarFile = fullfile(matlabroot,'/java/jar/mwt.jar');
iconsFolder = '/com/mathworks/mwt/resources/';
iconURI = ['jar:file:/' jarFile '!' iconsFolder 'closebox.gif'];
icon = javax.swing.ImageIcon(java.net.URL(iconURI));
% Now let's prepare the close button: icon, size and callback
jCloseButton = handle(javax.swing.JButton,'CallbackProperties');
jCloseButton.setIcon(icon);
jCloseButton.setPreferredSize(java.awt.Dimension(15,15));
jCloseButton.setMaximumSize(java.awt.Dimension(15,15));
jCloseButton.setSize(java.awt.Dimension(15,15));
set(jCloseButton, 'ActionPerformedCallback',@(h,e)delete(tab2));
% Now let's prepare a tab panel with our label and close button
jPanel = javax.swing.JPanel;	% default layout = FlowLayout
set(jPanel.getLayout, 'Hgap',0, 'Vgap',0);  % default gap = 5px
jLabel = javax.swing.JLabel('Tab #2');
jPanel.add(jLabel);
jPanel.add(jCloseButton);
% Now attach this tab panel as the tab-group's 2nd component
jTabGroup.setTabComponentAt(1,jPanel);	% Tab #1 = second tab
</pre>
<p><center><figure style="width: 359px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="tab with an attached close button" src="https://undocumentedmatlab.com/images/uitabgroup8_close_button.png" title="tab with an attached close button" width="359" height="185" /><figcaption class="wp-caption-text">tab with an attached close button</figcaption></figure></center><br />
Next week&#8217;s article will conclude the series on Matlab&#8217;s <i><b>uitab</b></i>. Any particular customization you are interested in? Please do post a <a target="_blank" href="/articles/uitab-colors-icons-images/#respond">comment</a>.<br />
<b><u>Addendum Oct 3 2014</u></b>: the <i><b>uitab</b></i> and <i><b>uitabgroup</b></i> functions have finally become fully supported and documented in Matlab version 8.4 (R2014b). However, the Java-based customizations shown in this article are still unsupported and undocumented, although they remain practically unchanged from what I&#8217;ve described in this article, four years earlier.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitab-colors-icons-images">Uitab colors, icons and images</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/uitab-customizations" rel="bookmark" title="Uitab customizations">Uitab customizations </a> <small>This article shows several customizations that can be done to Matlab's undocumented tab-panels functionality...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-system-tray-icons" rel="bookmark" title="Setting system tray icons">Setting system tray icons </a> <small>System-tray icons can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitab-colors-icons-images/feed</wfw:commentRss>
			<slash:comments>43</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing uitree nodes &#8211; part 2</title>
		<link>https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-uitree-nodes-2</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 01 Sep 2010 08:00:57 +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[Semi-documented function]]></category>
		<category><![CDATA[uitools]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1850</guid>

					<description><![CDATA[<p>This article shows how Matlab GUI tree nodes can be customized with checkboxes and similar controls</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2">Customizing uitree nodes &#8211; 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-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>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree" rel="bookmark" title="Customizing uitree">Customizing uitree </a> <small>This article describes how to customize Matlab GUI tree controls created using the undocumented uitree function...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility" rel="bookmark" title="An interesting uitree utility">An interesting uitree utility </a> <small>ExploreStruct is a utility that shows how custom uitrees can be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitree" rel="bookmark" title="uitree">uitree </a> <small>This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In my previous posts I have shown how Matlab&#8217;s semi-documented <i><b>uitree</b></i> and <i><b>uitreenode</b></i> functions can be used to display hierarchical (tree) control in Matlab GUI. Today I conclude this mini-series by answering a reader&#8217;s <a target="_blank" href="/articles/customizing-uitree/#comment-15781">request</a> to show how checkboxes, radio buttons and other similar controls can be attached to tree nodes.<br />
There are actually several ways this can be done:</p>
<h3 id="Matlab-icon">Matlab icon control</h3>
<p>The simplest is to create two icons (checked/unchecked) and switch the node&#8217;s icon whenever it is selected (use mtree&#8217;s <strong>NodeSelectedCallback</strong> or jtree&#8217;s <strong>MouseClickedCallback</strong> callbacks) &#8211; a sample implementation was posted by <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/164189#416971">Gwendolyn Fischer</a> a couple of years ago, based on even earlier posts by <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/104957#269485">John Anderson</a>, <a target="_blank" rel="nofollow" href="http://web.archive.org/web/20071015115312/xtargets.com/cms/Tutorials/Matlab-Programming/Handle-Graphics-Tree-Control-With-Nested-Functions.html">Brad Phelan</a> and me. Here it is, with minor fixes:</p>
<pre lang="matlab">
function uitree_demo
% function based on treeExperiment6 by John Anderson
% see https://www.mathworks.com/matlabcentral/newsreader/view_thread/104957#269485
%
% The mousePressedCallback part is inspired by Yair Altman
%
% derived from Brad Phelan's tree demo
% create a tree model based on UITreeNodes and insert into uitree.
% add and remove nodes from the treeModel and update the display
import javax.swing.*
import javax.swing.tree.*;
% figure window
f = figure('Units', 'normalized');
b1 = uicontrol( 'string','add Node', ...
   'units' , 'normalized', ...
   'position', [0 0.5 0.5 0.5], ...
   'callback', @b1_cb);
b2 = uicontrol( 'string','remove Node', ...
   'units' , 'normalized', ...
   'position', [0.5 0.5 0.5 0.5], ...
   'callback', @b2_cb);
%[I,map] = imread([matlab_work_path, '/checkedIcon.gif']);
[I,map] = checkedIcon;
javaImage_checked = im2java(I,map);
%[I,map] = imread([matlab_work_path, '/uncheckedIcon.gif']);
[I,map] = uncheckedIcon;
javaImage_unchecked = im2java(I,map);
% javaImage_checked/unchecked are assumed to have the same width
iconWidth = javaImage_unchecked.getWidth;
% create top node
rootNode = uitreenode('v0','root', 'File List', [], 0);
% [matlab_work_path, '/fileListIcon.gif'],0);
% create two children with checkboxes
cNode = uitreenode('v0','unselected', 'File A', [], 0);
% as icon is embedded here we set the icon via java, otherwise one could
% use the uitreenode syntax uitreenode(value, string, icon, isLeaf) with
% icon being a qualified pathname to an image to be used.
cNode.setIcon(javaImage_unchecked);
rootNode.add(cNode);
cNode = uitreenode('v0','unselected', 'File B', [], 0);
cNode.setIcon(javaImage_unchecked);
rootNode.add(cNode);
% set treeModel
treeModel = DefaultTreeModel( rootNode );
% create the tree
tree = uitree('v0');
tree.setModel( treeModel );
% we often rely on the underlying java tree
jtree = handle(tree.getTree,'CallbackProperties');
% some layout
drawnow;
set(tree, 'Units', 'normalized', 'position', [0 0 1 0.5]);
set(tree, 'NodeSelectedCallback', @selected_cb );
% make root the initially selected node
tree.setSelectedNode( rootNode );
% MousePressedCallback is not supported by the uitree, but by jtree
set(jtree, 'MousePressedCallback', @mousePressedCallback);
  % Set the mouse-press callback
  function mousePressedCallback(hTree, eventData) %,additionalVar)
  % if eventData.isMetaDown % right-click is like a Meta-button
  % if eventData.getClickCount==2 % how to detect double clicks
  % Get the clicked node
    clickX = eventData.getX;
    clickY = eventData.getY;
    treePath = jtree.getPathForLocation(clickX, clickY);
    % check if a node was clicked
    if ~isempty(treePath)
      % check if the checkbox was clicked
      if clickX <= (jtree.getPathBounds(treePath).x+iconWidth)
        node = treePath.getLastPathComponent;
        nodeValue = node.getValue;
        % as the value field is the selected/unselected flag,
        % we can also use it to only act on nodes with these values
        switch nodeValue
          case 'selected'
            node.setValue('unselected');
            node.setIcon(javaImage_unchecked);
            jtree.treeDidChange();
          case 'unselected'
            node.setValue('selected');
            node.setIcon(javaImage_checked);
            jtree.treeDidChange();
        end
      end
    end
  end % function mousePressedCallback
  function selected_cb( tree, ev )
    nodes = tree.getSelectedNodes;
    node = nodes(1);
    path = node2path(node);
  end
  function path = node2path(node)
    path = node.getPath;
    for i=1:length(path);
      p{i} = char(path(i).getName);
    end
    if length(p) > 1
      path = fullfile(p{:});
    else
      path = p{1};
    end
  end
  % add node
  function b1_cb( h, env )
    nodes = tree.getSelectedNodes;
    node = nodes(1);
    parent = node;
    childNode = uitreenode('v0','dummy', 'Child Node', [], 0);
    treeModel.insertNodeInto(childNode,parent,parent.getChildCount());
    % expand to show added child
    tree.setSelectedNode( childNode );
    % insure additional nodes are added to parent
    tree.setSelectedNode( parent );
  end
  % remove node
  function b2_cb( h, env )
    nodes = tree.getSelectedNodes;
    node = nodes(1);
    if ~node.isRoot
      nP = node.getPreviousSibling;
      nN = node.getNextSibling;
      if ~isempty( nN )
        tree.setSelectedNode( nN );
      elseif ~isempty( nP )
        tree.setSelectedNode( nP );
      else
        tree.setSelectedNode( node.getParent );
      end
      treeModel.removeNodeFromParent( node );
    end
  end
end % of main function treeExperiment6
  function [I,map] = checkedIcon()
    I = uint8(...
        [1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0;
         2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,1;
         2,2,2,2,2,2,2,2,2,2,2,2,0,2,3,1;
         2,2,1,1,1,1,1,1,1,1,1,0,2,2,3,1;
         2,2,1,1,1,1,1,1,1,1,0,1,2,2,3,1;
         2,2,1,1,1,1,1,1,1,0,1,1,2,2,3,1;
         2,2,1,1,1,1,1,1,0,0,1,1,2,2,3,1;
         2,2,1,0,0,1,1,0,0,1,1,1,2,2,3,1;
         2,2,1,1,0,0,0,0,1,1,1,1,2,2,3,1;
         2,2,1,1,0,0,0,0,1,1,1,1,2,2,3,1;
         2,2,1,1,1,0,0,1,1,1,1,1,2,2,3,1;
         2,2,1,1,1,0,1,1,1,1,1,1,2,2,3,1;
         2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
         2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
         2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
         1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1]);
     map = [0.023529,0.4902,0;
            1,1,1;
            0,0,0;
            0.50196,0.50196,0.50196;
            0.50196,0.50196,0.50196;
            0,0,0;
            0,0,0;
            0,0,0];
  end
  function [I,map] = uncheckedIcon()
     I = uint8(...
       [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,1,1,1,1,1,1,1,1,1,1,2,2,3,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,1;
        1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1]);
     map = ...
      [0.023529,0.4902,0;
       1,1,1;
       0,0,0;
       0.50196,0.50196,0.50196;
       0.50196,0.50196,0.50196;
       0,0,0;
       0,0,0;
       0,0,0];
  end
</pre>
<p><center><figure style="width: 359px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uitree with custom checkbox icons" src="https://undocumentedmatlab.com/images/uitree8.png" title="uitree with custom checkbox icons" width="359" height="283" /><figcaption class="wp-caption-text">uitree with custom checkbox icons</figcaption></figure></center></p>
<h3 id="Custom-Java">Custom Java classes</h3>
<p>An alternative is to create a custom tree Java class and/or a custom <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/tree/DefaultTreeCellRenderer.html">TreeCellRenderer</a>/<a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/tree/DefaultTreeCellEditor.html">TreeCellEditor</a>. Specifically, to change the icons of each node you have to implement your own java component which derives from <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/tree/DefaultMutableTreeNode.html">DefaultMutableTreeNode</a>.<br />
Some online resources to get you started:</p>
<ul>
<li>Sun&#8217;s official <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">JTree customization tutorial</a></li>
<li>Santhosh Kumar&#8217;s <a target="_blank" rel="nofollow" href="http://www.jroller.com/santhosh/entry/coloring_icons">custom tree icons</a>, <a target="_blank" rel="nofollow" href="http://www.jroller.com/santhosh/entry/jtree_with_checkboxes">tree-node checkboxes</a>, and <a target="_blank" rel="nofollow" href="http://www.jroller.com/santhosh/entry/show_checkboxes_only_on_specific">selective tree-node checkboxes</a></li>
<li>Java2s&#8217;s multiple <a target="_blank" rel="nofollow" href="http://www.java2s.com/Code/Java/Swing-JFC/Tree.htm">JTree customization snippets</a></li>
</ul>
<h3 id="Built-in-classes">Built-in classes</h3>
<p>Another option is to use Matlab&#8217;s built-in classes, either com.mathworks.mwswing.checkboxtree.CheckBoxTree or com.jidesoft.swing.CheckBoxTree:</p>
<pre lang="matlab">
import com.mathworks.mwswing.checkboxtree.*
jRoot = DefaultCheckBoxNode('Root');
l1a = DefaultCheckBoxNode('Letters'); jRoot.add(l1a);
l1b = DefaultCheckBoxNode('Numbers'); jRoot.add(l1b);
l2a = DefaultCheckBoxNode('A'); l1a.add(l2a);
l2b = DefaultCheckBoxNode('b'); l1a.add(l2b);
l2c = DefaultCheckBoxNode('<html><b>&alpha;'); l1a.add(l2c);
l2d = DefaultCheckBoxNode('<html><i>&beta;'); l1a.add(l2d);
l2e = DefaultCheckBoxNode('3.1415'); l1b.add(l2e);
% Present the standard MJTree:
jTree = com.mathworks.mwswing.MJTree(jRoot);
jScrollPane = com.mathworks.mwswing.MJScrollPane(jTree);
[jComp,hc] = javacomponent(jScrollPane,[10,10,120,110],gcf);
% Now present the CheckBoxTree:
jCheckBoxTree = CheckBoxTree(jTree.getModel);
jScrollPane = com.mathworks.mwswing.MJScrollPane(jCheckBoxTree);
[jComp,hc] = javacomponent(jScrollPane,[150,10,120,110],gcf);
</pre>
<p><center><figure style="width: 311px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="a regular MJTree (left) and a CheckBoxTree (right)" src="https://undocumentedmatlab.com/images/CheckBoxTree.png" title="a regular MJTree (left) and a CheckBoxTree (right)" width="311" height="218" /><figcaption class="wp-caption-text">a regular MJTree (left) and a CheckBoxTree (right)</figcaption></figure></center><br />
Note: Matlab&#8217;s CheckBoxTree does not have a separate data model. Instead, it relies on the base MJTree&#8217;s model, which is a <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/tree/DefaultTreeModel.html">DefaultTreeModel</a> by default. JIDE&#8217;s CheckBoxTree does have its own model.<br />
This concludes my <i><b>uitree</b></i> mini-series. If you have any special customizations, please post a comment <a href="/articles/customizing-uitree-nodes-2/#respond">below</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2">Customizing uitree nodes &#8211; 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-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>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uitree" rel="bookmark" title="Customizing uitree">Customizing uitree </a> <small>This article describes how to customize Matlab GUI tree controls created using the undocumented uitree function...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility" rel="bookmark" title="An interesting uitree utility">An interesting uitree utility </a> <small>ExploreStruct is a utility that shows how custom uitrees can be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitree" rel="bookmark" title="uitree">uitree </a> <small>This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-uitree-nodes-2/feed</wfw:commentRss>
			<slash:comments>61</slash:comments>
		
		
			</item>
	</channel>
</rss>
