<?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>uitable &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/uitable/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>treeTable</title>
		<link>https://undocumentedmatlab.com/articles/treetable?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=treetable</link>
					<comments>https://undocumentedmatlab.com/articles/treetable#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 06 Aug 2013 07:10:20 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<category><![CDATA[uitree]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4062</guid>

					<description><![CDATA[<p>A description of a sortable, groupable tree-table control that can be used in Matlab is provided. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/treetable">treeTable</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-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/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Since Matlab 7.0 (R14), Matlab has included a built-in GUI table control (<i><b>uitable</b></i>), at first as a <a target="_blank" href="/articles/legend-semi-documented-feature/#Semi-documented">semi-documented</a> function and in release 7.6 (R2008a) as a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/uitable.html">fully-documented</a> function. Useful as this control is, it lacks many features that are expected in modern GUIs, including sorting, filtering, cell-specific appearance and behavior, gridline customization etc. In <a target="_blank" href="/articles/tag/uitable/">past articles</a> I have explained how <i><b>uitable</b></i> can be customized to achieve a more professional-looking table. I expanded on this in my <a target="_blank" href="/matlab-java-book/">book</a> and my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a>.<br />
Today I explain how a grouping hierarchy can be achieved in a table control that can be used in Matlab GUI. Such a control, which is a combination of a <a target="_blank" href="/articles/uitree/"><i><b>uitree</b></i></a> and <i><b>uitable</b></i>, is typically called a <i>tree-table</i>. We can find numerous examples of it in everyday usage. I have encapsulated the functionality in a utility called <i><b>treeTable</b></i> on the Matlab File Exchange (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/42946-treetable-create-a-sortable-table-control-with-collapsible-row-groups">#42946</a>). The utility is provided with full source code and open-source license, and readers are welcome to use and modify it. A detailed explanation of the technicalities follows below, but if you&#8217;re just interested in having a sortable, rearrangeable, customizable, groupable table control, then all you need to do is download and use the utility.<br />
<figure style="width: 407px" class="wp-caption alignright"><img fetchpriority="high" decoding="async" alt="treeTable utility" src="https://undocumentedmatlab.com/images/treeTable.jpg" title="treeTable utility" width="407" height="364" /><figcaption class="wp-caption-text">treeTable utility</figcaption></figure></p>
<pre lang='matlab'>
headers = {'ID','Label','Logical1','Logical2','Selector','Numeric'};
data = {1,'M11',true, false,'One', 1011;  ...
        1,'M12',true, true, 'Two', 12;   ...
        1,'M13',false,false,'Many',13.4; ...
        2,'M21',true, false,'One', 21;  ...
        2,'M22',true, true, 'Two', 22;   ...
        3,'M31',true, true, 'Many',31;   ...
        3,'M32',false,true, 'One', -32;  ...
        3,'M33',false,false,'Two', 33; ...
        3,'M34',true, true, 'Many',34;  ...
};
selector = {'One','Two','Many'};
colTypes = {'label','label','char','logical',selector,'double'};
colEditable = {true, true, true, true, true}
icons = {fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/file_open.png'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/foldericon.gif'), ...
}
% Create the table in the current figure
jtable = treeTable('Container',gcf, 'Headers',headers, 'Data',data, ...
                   'ColumnTypes',colTypes, 'ColumnEditable',colEditable, ...
                   'IconFilenames',icons, 'Groupable',true, 'InteractiveGrouping',false);
% Collapse Row #6, sort descending column #5 (both are 0-based)
jtable.expandRow(5,false);  % 5=row #6; false=collapse
jtable.sortColumn(4,true,false);  % 4=column #5; true=primary; false=descending
</pre>
<p><span id="more-4062"></span></p>
<h3 id="implementation">The basic implementation concept</h3>
<p>Unfortunately, <i><b>uitable</b></i> as-is cannot be customized to have groupable rows. It derives from JIDE&#8217;s <code>SortableTable</code>, rather than one of its groupable derived classes. On the other hand, <i><b>uitree</b></i> (<i>don&#8217;t you agree that after a decade of this so-useful function being semi-documented it ought to be made official?</i>) uses a different class hierarchy outside <code>com.jidesoft.grid</code>, and so it cannot be easily customized to display rows (as opposed to simple labels).<br />
These limitations mean that we cannot use <i><b>uitable</b></i> or <i><b>uitree</b></i> and need to use a custom component. Luckily, such a component is available in all Matlab installations, on all platforms. It is part of the grid components package, on which Matlab GUI has relied for many years, by <a target="_blank" rel="nofollow" href="http://www.jidesoft.com">JIDE Software</a>. JIDE Grids is a collection of components that extend the standard Java Swing <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">JTable</a> component, and is included in each Matlab installation (<i>/java/jarext/jide/jide-grids.jar</i> under the Matlab root). I discussed <a target="_blank" href="/articles/tag/jide/">multiple JIDE controls</a> in this blog over the years. You can find further details on JIDE Grids in the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf">Developer Guide</a> and the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/">Javadoc documentation</a>.<br />
In fact, there are no less than three different components that we could use in our case: <code>TreeTable</code>, <code>GroupTable</code> and <code>HierarchicalTable</code>:<br />
<center><figure style="width: 417px" class="wp-caption aligncenter"><img decoding="async" alt="JIDE Grids class hierarchy (we normally use only one of the marked classes)" src="https://undocumentedmatlab.com/images/JIDE_Grids.png" title="JIDE Grids class hierarchy (we normally use only one of the marked classes)" width="417" height="233"/><figcaption class="wp-caption-text">JIDE Grids class hierarchy (we normally use only one of the marked classes)</figcaption></figure></center><br />
Note that we cannot use <code>PropertyTable</code> since that component is limited to only two columns. This is perfect for presenting property names and values, which is the reason it is used by Matlab&#8217;s <i><b>inspect</b></i> function and my generic <a target="_blank" href="/articles/propertiesgui/"><i><b>propertiesGUI</b></i> utility</a> or Levente Hunyadi&#8217;s <a target="_blank" href="/articles/jide-property-grids/">Property Grid utility</a>. But in this case we wish to display a general multi-column table, so <code>PropertyTable</code> is a no-go.<br />
<code>TreeTable</code> and <code>GroupTable</code> enable data rows that have similar type (class), whereas <code>HierarchicalTable</code> enables more flexibility, by allowing display of any component type (including full tables) in child rows. This flexibility comes with a price that customizing a <code>HierarchicalTable</code> is more difficult than <code>TreeTable</code> or <code>GroupTable</code>. These latter two components are quite similar; we use <code>GroupTable</code>, which extends <code>TreeTable</code> with the ability to automatically group rows that have the same value in a certain column.</p>
<h3 id="model">Data model</h3>
<p>The above-mentioned table classes all derive from <code>SortableTable</code> (which also underlies <i><b>uitable</b></i>). Unfortunately, something in the Matlab-Java interface breaks the ability of the JIDE table classes (or rather, their data model) to understand numeric values for what they are. As a result, sorting columns is done lexically, i.e. &#8220;123&#8221; &lt; &#8220;34&#8221; &lt; &#8220;9&#8221;. To fix this, I&#8217;ve included a custom Java table model (<code>MultiClassTableModel</code>) with the <i><b>treeTable</b></i> utility, which automatically infers the column type (class) based on the value in the top row (by overriding the <i>getColumnClass()</i> method).<br />
Using this new class is pretty easy:</p>
<pre lang='matlab'>
% Create the basic data-type-aware model using our data and headers
javaaddpath(fileparts(mfilename('fullpath')));  % add the Java class file to the dynamic java class-path
model = MultiClassTableModel(data, headers);  % data=2D cell or numeric array; headers=cell array of strings
% Wrap the standard model in a JIDE GroupTableModel
com.mathworks.mwswing.MJUtilities.initJIDE;  % initialize JIDE
model = com.jidesoft.grid.DefaultGroupTableModel(model);
model.addGroupColumn(0);  % make the first column the grouping column
model.groupAndRefresh;  % update the model data
% Use the generated model as the data-model of a JIDE GroupTable
jtable = eval('com.jidesoft.grid.GroupTable(model);');  % prevent JIDE alert by run-time (not load-time) evaluation
jtable = handle(javaObjectEDT(jtable), 'CallbackProperties');  % ensure that we're using EDT
% Enable multi-column sorting
jtable.setSortable(true);
% Present the tree-table within a scrollable viewport on-screen
scroll = javaObjectEDT(JScrollPane(jtable));
[jhscroll,hContainer] = javacomponent(scroll, tablePosition, hParent);
set(hContainer,'units', 'normalized','pos',[0,0,1,1]);  % this will resize the table whenever its container is resized
</pre>
<p>Here, <em>com.mathworks.mwswing.MJUtilities.initJIDE</em> is called to initialize JIDE&#8217;s usage within Matlab. Without this call, we may see a JIDE warning message in some Matlab releases. We only need to <em>initJIDE</em> once per Matlab session, although there is no harm in repeated calls.<br />
<i><b>javacomponent</b></i> is the undocumented built-in Matlab function that adds Java Swing components to a Matlab figure, using the given dimensions and parent handle. I discussed it <a target="_blank" href="/articles/javacomponent/">here</a>.</p>
<h3 id="callbacks">Callbacks</h3>
<p>There are two main callbacks that can be used with <i><b>treeTable</b></i>:</p>
<ul>
<li>table data update &#8211; this can be set by uncommenting line #237 of <i>treeTable.m</i>:
<pre lang='matlab'>set(handle(getOriginalModel(jtable),'CallbackProperties'), 'TableChangedCallback', {@tableChangedCallback, jtable});</pre>
<p>which activates the sample <code>tableChangedCallback()</code> function (lines #684-694). Naturally, you can also set your own custom callback function.</p>
<pre lang='matlab'>
% Sample table-editing callback
function tableChangedCallback(hModel,hEvent,jtable)
    % Get the modification data
    modifiedRow = get(hEvent,'FirstRow');
    modifiedCol = get(hEvent,'Column');
    label   = hModel.getValueAt(modifiedRow,1);
    newData = hModel.getValueAt(modifiedRow,modifiedCol);
    % Now do something useful with this info
    fprintf('Modified cell %d,%d (%s) to: %s\n', modifiedRow+1, modifiedCol+1, char(label), num2str(newData));
end  % tableChangedCallback
</pre>
</li>
<li>row selection update &#8211; this is currently enabled in line #238 of <i>treeTable.m</i>:
<pre lang='matlab'>set(handle(jtable.getSelectionModel,'CallbackProperties'), 'ValueChangedCallback', {@selectionCallback, jtable});</pre>
<p>which activates the sample <code>selectionCallback()</code> function (lines #696-705). Naturally, you can also set your own custom callback function.</p>
<pre lang='matlab'>
% Sample table-selection callback
function selectionCallback(hSelectionModel,hEvent,jtable)
    % Get the selection data
    MinSelectionIndex  = get(hSelectionModel,'MinSelectionIndex');
    MaxSelectionIndex  = get(hSelectionModel,'MaxSelectionIndex');
    LeadSelectionIndex = get(hSelectionModel,'LeadSelectionIndex');
    % Now do something useful with this info
    fprintf('Selected rows #%d-%d\n', MinSelectionIndex+1, MaxSelectionIndex+1);
end  % selectionCallback
</pre>
</li>
</ul>
<h3 id="features">Some useful features of <i>treeTable</i></h3>
<p><center><figure style="width: 342px" class="wp-caption alignright"><img decoding="async" alt="treeTable with InteractiveGrouping, multi-column sorting, column rearranging" src="https://undocumentedmatlab.com/images/treeTable_InteractiveGrouping.jpg" title="treeTable with InteractiveGrouping, multi-column sorting, column rearranging" width="342" height="366" /><figcaption class="wp-caption-text">treeTable with interactive grouping, multi-column sorting, column rearranging</figcaption></figure></center></p>
<ul>
<li>Sortable columns (including numeric columns)</li>
<li>Rearrangeable columns (drag headers left/right)</li>
<li>Auto-fit the table columns into the specified container width</li>
<li>Manually resize columns by dragging the column divider gridlines (not just the header dividers as in <i><b>uitable</b></i>)</li>
<li>Flat or groupable table, based on the specified <b>Groupable</b> parameter (default=true)</li>
<li>Ability to interactively group columns (just like Microsoft Outlook) using the <b>InteractiveGrouping</b> parameter (default=false)</li>
<li>Selector cells only show the drop-down arrow of the currently-selected cell (unlike <i><b>uitable</b></i> which shows it for all the column cells)</li>
<li>Selector cells enable editing, unlike <i><b>uitable</b></i> that only enables selecting among pre-defined values</li>
<li>Ability to attach user-defined icons for the leaf rows and the grouping rows (expanded/collapsed)</li>
<li>Easily attach custom cell editors or renderers to any table column (see my <a target="_blank" href="/matlab-java-book/">book</a> and my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a> for details)</li>
</ul>
<p>All of these features can be turned on/off using the control&#8217;s properties. Again, see my book or report for details (or <a target="_blank" href="/consulting/">ask me</a> to do it for you&#8230;).<br />
I remind readers that I will be visiting clients in Austria (Vienna, Salzburg) and Switzerland (Zurich) in August 18-29. If you live in the area, I will be happy to meet you to discuss how I could bring value to your needs, as consultant, contractor or trainer (<a target="_blank" href="/articles/sparse-data-math-info/#visit">more details</a>).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/treetable">treeTable</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-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/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/treetable/feed</wfw:commentRss>
			<slash:comments>90</slash:comments>
		
		
			</item>
		<item>
		<title>Real-time trading system demo</title>
		<link>https://undocumentedmatlab.com/articles/real-time-trading-system-demo?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=real-time-trading-system-demo</link>
					<comments>https://undocumentedmatlab.com/articles/real-time-trading-system-demo#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 29 May 2013 13:15:21 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[uisplitpane]]></category>
		<category><![CDATA[uitable]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3825</guid>

					<description><![CDATA[<p>A real-time Matlab-based end-to-end trading system demo is presented </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo">Real-time trading system demo</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo" rel="bookmark" title="JTattoo look-and-feel demo">JTattoo look-and-feel demo </a> <small>A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/nyc-visit-may-2013" rel="bookmark" title="New York City visit, 21-24 May 2013">New York City visit, 21-24 May 2013 </a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I gave a presentation at the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/agenda.html">MATLAB Computational Finance Conference</a> in New York. The room was packed-full with close to 200 professionals in the finance industry. The energy and feedback were tremendous, it was a great experience. The presentation (PDF format) is provided <a target="_blank" href="/files/Matlab%20real-time%20trading%20presentation.pdf">here</a>.<br />
I presented a demo application that showed how Matlab can be used to create a full end-to-end trading system, highlighting Matlab&#8217;s potential as a platform of choice. I used <a target="_blank" rel="nofollow" href="http://www.interactivebrokers.com/en/main.php">Interactive Brokers</a> to demonstrate live market data feed and account/portfolio input, as well as for sending trading orders to the market, via the <a target="_blank" href="/ib-matlab/">IB-Matlab</a> connector:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" href="/images/demo_screenshot.png"><img loading="lazy" decoding="async" alt="Real-time trading system demo in Matlab (click for details)" src="https://undocumentedmatlab.com/images/demo_screenshot.png" title="Real-time trading system demo in Matlab (click for details)" width="560" height="289" /></a><figcaption class="wp-caption-text">Real-time trading system demo in Matlab (click for details)</figcaption></figure></center><br />
The demo system&#8217;s user interface showcased the hidden visualization and interactivity potential of MATLAB for tracking order executions and charting financial time-series in real time. The undocumented features used in the demo include:</p>
<ul>
<li><a target="_blank" href="/articles/displaying-animated-gifs/">Animated GIF logo image</a> (rotating Dollar sign)</li>
<li><a target="_blank" href="/articles/uitable-customization-report/">Customized data table</a></li>
<li><a target="_blank" href="/articles/rich-matlab-editbox-contents/">Log box with rich HTML contents</a>: icons and color-coded messages</li>
<li><a target="_blank" href="/articles/uisplitpane/">Draggable (resizable) panel borders</a> (note that this feature does not work in the new <a target="_blank" href="/articles/hg2-update/">HG2</a> &#8211; I hope it will be fixed by the time that HG2 is released)</li>
<li><a target="_blank" href="/articles/minimize-maximize-figure-window/">Maximized figure window</a></li>
</ul>
<p>The demo source code is provided <a target="_blank" href="/files/Matlab%20trading%20demo.zip">here</a> (tradingDemo.m and supporting files). Note that this is provided as-is, free of charge but without any warranty or support. You would naturally need <a target="_blank" href="/ib-matlab/">IB-Matlab</a> and an Interactive Brokers account to run it.<br />
If you came to the conference, I want to thank you for being an excellent audience. I hope we have a chance to work together on your projects. Shoot me <a href="mailto: altmany @gmail.com?subject=Matlab assistance&amp;body=Hi Yair, &amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab assistance&amp;body=Hi Yair, '); return false;">an email</a> if you&#8217;d like my help in any consulting, training or development work.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/real-time-trading-system-demo">Real-time trading system demo</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo" rel="bookmark" title="JTattoo look-and-feel demo">JTattoo look-and-feel demo </a> <small>A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/nyc-visit-may-2013" rel="bookmark" title="New York City visit, 21-24 May 2013">New York City visit, 21-24 May 2013 </a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/rich-contents-log-panel" rel="bookmark" title="Rich-contents log panel">Rich-contents log panel </a> <small>Matlab listboxes and editboxes can be used to display rich-contents HTML-formatted strings, which is ideal for log panels. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/real-time-trading-system-demo/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Multi-line uitable column headers</title>
		<link>https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multi-line-uitable-column-headers</link>
					<comments>https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 27 Jun 2012 22:54:40 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uitable]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2976</guid>

					<description><![CDATA[<p>Matlab uitables can present long column headers in multiple lines, for improved readability. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers">Multi-line uitable column headers</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/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-tooltips" rel="bookmark" title="Multi-line tooltips">Multi-line tooltips </a> <small>Multi-line tooltips are very easy to set up, once you know your way around a few undocumented hiccups....</small></li>
<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-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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I often need to present data in tabular format in Matlab GUI, and this data often has relatively long column headers such as &#8220;Maximal draw/gain&#8221; or &#8220;Coefficient of elasticity&#8221;. When the table has many columns, these long column headers do not fit in the small space that is available:</p>
<pre lang='matlab'>uitable('data',magic(2),'ColumnName',{'Maximal draw/gain','Coefficient of elasticity'})</pre>
<p><center><figure style="width: 220px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Default uitable behavior with long headers" src="https://undocumentedmatlab.com/images/uitable_headers1.png" title="Default uitable behavior with long headers" width="186" height="55"/><figcaption class="wp-caption-text">Default uitable behavior with long headers</figcaption></figure></center></p>
<h3 id="split">Creating multi-line headers</h3>
<p>It makes sense to split such long column headers into a multi-line string. In the new (R2008a+) <i><b>uitable</b></i>, this can easily be done by adding the | character wherever we wish the line to be split; in both the new and the old <i><b>uitable</b></i>, we can also use the <a target="_blank" href="/articles/multi-line-tooltips/#HTML">built-in HTML support</a> by adding a simple <code>&lt;br/&gt;</code>. The following code snippet demonstrates both of these alternatives:</p>
<pre lang='matlab'>uitable('data',magic(2), 'ColumnName',{'Maximal|draw/gain', '<html><center />Coefficient<br />of elasticity</html>'});</pre>
<p><center><figure style="width: 181px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Multi-line uitable headers" src="https://undocumentedmatlab.com/images/uitable_headers2.png" title="Multi-line uitable headers" width="181" height="71"/><figcaption class="wp-caption-text">Multi-line uitable headers</figcaption></figure></center><br />
Much more readable and useful, I think. Note that HTML code is left-aligned by default, so to center the header I added the <code>&lt;center&gt;</code> tag in the snippet.<br />
If the text appears too crowded in the header cells, we can slightly reduce the header font, to make it appear more spaced-out. The following snippet illustrates this for the old <i><b>uitable</b></i> (available since Matlab 7.0 all the way until today), which can only use the HTML alternative since it does not support |:</p>
<pre lang='matlab'>
headers = {'<html>Maximal<br />draw/gain</html>', ...
           '<html><center /><font size=-2>Coefficient<br />of elasticity</font></html>'};
uitable('v0','data',magic(2),'ColumnNames',headers);
</pre>
<p><center><figure style="width: 166px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Multi-line headers in the old uitable" src="https://undocumentedmatlab.com/images/uitable_headers3.png" title="Multi-line headers in the old uitable" width="166" height="61"/><figcaption class="wp-caption-text">Multi-line headers in the old uitable</figcaption></figure></center></p>
<h3 id="dynamic">Dynamic multi-line headers</h3>
<p>While adding | or <code>&lt;br/&gt;</code> solves the problem for the majority of cases, it is sometimes difficult to know in advance where to place the line-split. This often happens when the column headers are dynamically generated by the program. If we omit the <code>&lt;br/&gt;</code> from our header strings, we get sub-optimal rendering: The new <i><b>uitable</b></i> simply hides all overflow terms, and the old <i><b>uitable</b></i> pushes them to the bottom:</p>
<pre lang='matlab'>
headers = {'<html>Maximal draw/gain</html>', ...
           '<html><center /><font size=-2>Coefficient of elasticity</font></html>'};
uitable('v0','data',magic(2),'ColumnNames',headers);
</pre>
<p><center><figure style="width: 166px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Default dynamic HTML multi-line (old uitable)" src="https://undocumentedmatlab.com/images/uitable_headers4.png" title="Default dynamic HTML multi-line (old uitable)" width="166" height="61"/><figcaption class="wp-caption-text">Default dynamic HTML multi-line (old uitable)</figcaption></figure></center><br />
I&#8217;ve tried numerous things, including CSS wrapping directives etc. None seem to work (I&#8217;ll be happy to hear a new idea that does work), except for the following weird-sounding trick: add a &#8220;<code>&lt;br/&gt;&amp;nbsp;</code>&#8221; at the <u>end</u> of the HTML header string. If the column is wide enough, then this will be disregarded; otherwise, it will automatically split the string nicely:</p>
<pre lang='matlab'>
headers = {'<html>Maximal draw/gain<br />&nbsp;</html>', ...
           '<html><center /><font size=-2>Coefficient of elasticity<br />&nbsp;</font></html>'};
uitable('v0','data',magic(2),'ColumnNames',headers);
</pre>
<p><center><figure style="width: 166px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Nicely-behaved dynamic HTML multi-lines" src="https://undocumentedmatlab.com/images/uitable_headers5.png" title="Nicely-behaved dynamic HTML multi-lines" width="166" height="61"/><figcaption class="wp-caption-text">Nicely-behaved dynamic HTML multi-lines</figcaption></figure></center><br />
Note: the <code>&amp;nbsp;</code> part is important &#8211; the trick will NOT work without it!</p>
<h3 id="controlling">Controlling the headers</h3>
<p>HTML provides some degree of control over the table header row. Some additional aspects can be configured by accessing the underlying Java&#8217;s TableHeader sub-component. But here&#8217;s another trick that I found handy: I hide the table header row altogether, and use the top table data row for my headers. I can control this row&#8217;s height using JTable&#8217;s standard <i>setRowHeight()</i> method. Using some fancy <a target="_blank" href="/articles/uitable-cell-colors/">cell background colors</a> I can make this row stand out, and I can easily control other aspects as well.<br />
The same trick can also be used for the row-header column: I can dispense with the standard one and use the table&#8217;s first column as a row-header column.<br />
For more information on <i><b>uitable</b></i> customization, refer to section 4.1 of my <a target="_blank" href="/matlab-java-book/">Matlab-Java book</a>, or to my <a target="_blank" href="/articles/uitable-customization-report/">uitable customization report</a>.<br />
Do you have a favorite trick with multi-line strings in Matlab GUI? If so, please share it in a comment <a target="_blank" href="/articles/multi-line-uitable-column-headers#respond">below</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers">Multi-line uitable column headers</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/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-line-tooltips" rel="bookmark" title="Multi-line tooltips">Multi-line tooltips </a> <small>Multi-line tooltips are very easy to set up, once you know your way around a few undocumented hiccups....</small></li>
<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-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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers/feed</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
			</item>
		<item>
		<title>Uitable cell colors</title>
		<link>https://undocumentedmatlab.com/articles/uitable-cell-colors?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uitable-cell-colors</link>
					<comments>https://undocumentedmatlab.com/articles/uitable-cell-colors#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 27 Oct 2011 01:51:53 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uitable]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2476</guid>

					<description><![CDATA[<p>A few Java-based customizations can transform a plain-looking data table into a lively colored one. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-cell-colors">Uitable cell colors</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-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/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/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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A client recently asked me to develop an application that will help discover technical indicators for trading on the stock market. The application was very data-intensive and the analysis naturally required visual presentations of number-crunching results in a readable manner. One of the requirements was to present numeric results in a data table, so we naturally use <i><b>uitable</b></i> for this.<br />
Today I will show how using some not-so-complex Java we can transform the standard Matlab <i><b>uitable</b></i> into something much more useful.</p>
<h3 id="basic">First pass &#8211; basic data table</h3>
<p>We start by displaying the data in a simple <i><b>uitable</b></i>. The essence of the relevant code snippet was something like this:</p>
<pre lang='matlab'>
headers = {'Periods', ...
           '<html><center>Any period<br />returns</center></html>', ...
           '<html><center>Avg return<br />signal</center></html>', ...
           '<html><center>Avg<br />gain</center></html>', ...
           '<html><center>Avg<br />draw</center></html>', ...
           '<html><center>Gain/draw<br />ratio</center></html>', ...
           '<html><center>Max<br />gain</center></html>', ...
           '<html><center>Max<br />draw</center></html>', ...
           '<html><center>Random<br />% pos</center></html>', ...
           '<html><center>Signal<br />% pos</center></html>', ...
           'Payout', '% p-value'};
hTable = uitable('Data',data, 'ColumnEditable',false, ...
           'ColumnName',headers, 'RowName',[], ...
           'ColumnFormat',['numeric',repmat({'bank'},1,11)], ...
           'ColumnWidth','auto', ...
           'Units','norm', 'Position',[0,.75,1,.25]);
</pre>
<p><center><figure style="width: 596px" class="wp-caption aligncenter"><img decoding="async" alt="Plain data table - so boooooring..." src="https://undocumentedmatlab.com/images/uitable_plain1.png" title="Plain data table - so boooooring..." width="596" /><figcaption class="wp-caption-text">Plain data table - so boooooring...</figcaption></figure></center><br />
We can see from this simple example how I have used HTML to format the header labels into two rows, to enable compact columns. I have already <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">described</a> using HTML formatting in Matlab controls in several articles on this website. I have not done this here, but you can easily use HTML formatting for other effect such as superscript (&lt;sup&gt;), subscript (&lt;sub&gt;), bold (&lt;b&gt;), italic (&lt;i&gt;), font sizes and colors (&lt;font&gt;) and other standard HTML effects.<br />
Even with the multi-line headers, the default column width appears to be too wide. This is apparently an internal Matlab bug, not taking HTML into consideration. This causes only part of the information to be displayed on screen, and requires the user to either scroll right and left, or to manually resize the columns.</p>
<h3 id="auto-resizing">Second pass &#8211; auto-resizing that actually works&#8230;</h3>
<p>To solve the auto-resizing issue, we resort to a bit of Java magic powder. We start by using the <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a> to get the table&#8217;s underlying Java reference handle. This is the containing scrollpane, and we are interested in the actual data table inside. We then use the <i>setAutoResizeMode</i>, as <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/javax/swing/JTable.html#setAutoResizeMode%28int%29">described</a> in the official Java documentation.</p>
<pre lang='matlab'>
jScroll = findjobj(hTable);
jTable = jScroll.getViewport.getView;
jTable.setAutoResizeMode(jTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
</pre>
<p><center><figure style="width: 596px" class="wp-caption aligncenter"><img decoding="async" alt="Auto-resized columns that actually work" src="https://undocumentedmatlab.com/images/uitable_plain2.png" title="Auto-resized columns that actually work" width="596" /><figcaption class="wp-caption-text">Auto-resized columns that actually work</figcaption></figure></center></p>
<h3 id="colors">Third pass &#8211; adding colors</h3>
<p>There are still quite a few other customizations needed here: enable <a target="_blank" href="/articles/uitable-sorting/">sorting</a>; remove the border outline; set a white background; set row (rather than cell) selection and several other fixes that may seem trivial by themselves but together giver a much more stylish look to the table&#8217;s look and feel. I&#8217;ll skip these for now (interested readers can read all about them, and more, in my detailed <a target="_blank" href="/articles/uitable-customization-report/"><i><b>uitable</b></i> customization report</a>).<br />
One of the more important customizations is to add colors depending on the data. In my client&#8217;s case, there were three requirements:</p>
<ul>
<li>data that could be positive or negative should be colored in <b><font color="green">green</font></b> or <b><font color="red">red</font></b> foreground color respectively</li>
<li>large payouts (abs &gt; 2) should be colored in <b><font color="blue">blue</font></b></li>
<li>data rows that have statistical significance (%p-value &lt; 5) should have a <span style="background-color:#ffff00;">yellow background highlight</span></li>
</ul>
<p>While we could easily use HTML or CSS formatting to do this, this would be bad for performance in a large data table, may cause some issues when editing table cells or sorting columns. I chose to use the alternative method of <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer">cell renderers</a>.<br />
<code>ColoredFieldCellRenderer</code> is a simple table cell renderer that enables setting cell-specific foreground/background colors and tooltip messages (it also has a few other goodies like smart text alignment etc.). This requires some Java knowledge to program, but in this case you can simply <a href="/files/ColoredFieldCellRenderer.zip">download</a> the ColoredFieldCellRenderer.zip file and use it, even if you don&#8217;t know Java. The source code is included in the zip file, for anyone who is interested.<br />
After using <i><b>javaaddpath</b></i> to add the zip file to the dynamic Java classpath (you can add it to the static <i>classpath.txt</i> file instead), the contained Java class file is available for use in Matlab. We configure it according to our data and then assign it to all our table&#8217;s columns.<br />
Java savvy readers might complain that the data-processing should perhaps be done in the renderer class rather than in Matlab. I have kept it in Matlab because this would enable very easy modification of the highlighting algorithm, without any need to modify the generic Java renderer class.<br />
Unfortunately, in the new <i><b>uitable</b></i> design (the version available since R2008a), JIDE and Matlab have apparently broken the <a target="_blank" rel="nofollow" href="http://java.sun.com/products/jfc/tsc/articles/architecture">standard MVC approach</a> by using a table model that not only controls the data but also sets the table&#8217;s appearance (row-striping background colors, for example), and disregards column cell-renderers. In order for our custom cell renderer to have any effect, we must therefore replace Matlab&#8217;s standard <code>DefaultUIStyleTableModel</code> with a simple <code>DefaultTableModel</code>. This in itself is not enough – we also need to ensure that the <i><b>uitable</b></i> has an empty <strong>ColumnFormat</strong> property, because if it is non-empty then it overrides our cell-renderer.<br />
In the following code, note that Java row and column indices start at 0, not at 1 like in Matlab. We need to be careful about indices when programming java in Matlab.<br />
The rest of the code should be pretty much self explanatory (again &#8211; more details can be found in the above-mentioned report):</p>
<pre lang='matlab'>
% Initialize our custom cell renderer class object
javaaddpath('ColoredFieldCellRenderer.zip');
cr = ColoredFieldCellRenderer(java.awt.Color.white);
cr.setDisabled(true);  % to bg-color the entire column
% Set specific cell colors (background and/or foreground)
for rowIdx = 1 : size(data,1)
  % Red/greed foreground color for the numeric data
  for colIdx = 2 : 8
    if data(rowIdx,colIdx) < 0
      cr.setCellFgColor(rowIdx-1,colIdx-1,java.awt.Color(1,0,0));    % red
    elseif data(rowIdx,colIdx) > 0
      cr.setCellFgColor(rowIdx-1,colIdx-1,java.awt.Color(0,0.5,0));  % green
    end
  end
  % Yellow background for significant rows based on p-value
  if data(rowIdx,12) < = 5 &#038;&#038; data(rowIdx,11)~=0
    for colIdx = 1 : length(headers)
      cr.setCellBgColor(rowIdx-1,colIdx-1,java.awt.Color(1,1,0));    % yellow
    end
  end
  % Bold blue foreground for significant payouts
  if abs(data(rowIdx,11)) >= 2
    cr.setCellFgColor(rowIdx-1,10,java.awt.Color(0,0,1));    % blue
    % Note: the following could easily be done in the renderer, just like the colors
    boldPayoutStr = ['<html><b>' num2str(data(rowIdx,11),'%.2f') '</b></html>'];
    %jTable.setValueAt(boldPayoutStr,rowIdx-1,10);  % this is no good: overridden when table model is replaced below...
    dataCells{rowIdx,11} = boldPayoutStr;
  end
end
% Replace Matlab's table model with something more renderer-friendly...
jTable.setModel(javax.swing.table.DefaultTableModel(dataCells,headers));
set(hTable,'ColumnFormat',[]);
% Finally assign the renderer object to all the table columns
for colIdx = 1 : length(headers)
  jTable.getColumnModel.getColumn(colIdx-1).setCellRenderer(cr);
end
</pre>
<p><center><figure style="width: 590px" class="wp-caption aligncenter"><img decoding="async" alt="Finally something lively!" src="https://undocumentedmatlab.com/images/uitable_colored.png" title="Finally something lively!" width="590" /><figcaption class="wp-caption-text">Finally something lively!</figcaption></figure></center><br />
This may not take a beauty contest prize, but you must admit that it now looks more useful than the original table at the top of this article.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uitable-cell-colors">Uitable cell colors</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-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/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/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uitable-cell-colors/feed</wfw:commentRss>
			<slash:comments>124</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>
	</channel>
</rss>
