<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Undocumented Matlab</title>
	<atom:link href="http://undocumentedmatlab.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://undocumentedmatlab.com</link>
	<description>Charting Matlab's unsupported hidden underbelly</description>
	<lastBuildDate>Wed, 01 Sep 2010 18:00:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Customizing uitree nodes &#8211; part 2</title>
		<link>http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/</link>
		<comments>http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 18:00:57 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<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[Icons]]></category>
		<category><![CDATA[uitools]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1850</guid>
		<description><![CDATA[This article shows how Matlab GUI tree nodes can be customized with checkboxes and similar controls

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol><pre> </pre>]]></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="http://undocumentedmatlab.com/blog/customizing-uitree/#comment-15781">request</a> to show how checkboxes, radio buttons and other similar controls can be attached to tree nodes.</p>
<p>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="http://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="http://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>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> uitree_demo
<span style="color: #228B22;">% function based on treeExperiment6 by John Anderson</span>
<span style="color: #228B22;">% see http://www.mathworks.com/matlabcentral/newsreader/view_thread/104957#269485</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% The mousePressedCallback part is inspired by Yair Altman</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% derived from Brad Phelan's tree demo</span>
<span style="color: #228B22;">% create a tree model based on UITreeNodes and insert into uitree.</span>
<span style="color: #228B22;">% add and remove nodes from the treeModel and update the display</span>
import javax.<span style="">swing</span>.*
import javax.<span style="">swing</span>.<span style="">tree</span>.*;
&nbsp;
<span style="color: #228B22;">% figure window</span>
f = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Units'</span>, <span style="color:#A020F0;">'normalized'</span><span style="color: #080;">&#41;</span>;
&nbsp;
b1 = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span> <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'add Node'</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'units'</span> , <span style="color:#A020F0;">'normalized'</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">0.5</span><span style="color: #080;">&#93;</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'callback'</span>, @b1_cb<span style="color: #080;">&#41;</span>;
&nbsp;
b2 = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span> <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'remove Node'</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'units'</span> , <span style="color:#A020F0;">'normalized'</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">0.5</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">0.5</span><span style="color: #080;">&#93;</span>, <span style="color: #F0F;">...</span>
   <span style="color:#A020F0;">'callback'</span>, @b2_cb<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%[I,map] = imread([matlab_work_path, '/checkedIcon.gif']);</span>
<span style="color: #080;">&#91;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#93;</span> = checkedIcon;
javaImage_checked = im2java<span style="color: #080;">&#40;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%[I,map] = imread([matlab_work_path, '/uncheckedIcon.gif']);</span>
<span style="color: #080;">&#91;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#93;</span> = uncheckedIcon;
javaImage_unchecked = im2java<span style="color: #080;">&#40;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% javaImage_checked/unchecked are assumed to have the same width</span>
iconWidth = javaImage_unchecked.<span style="">getWidth</span>;
&nbsp;
<span style="color: #228B22;">% create top node</span>
rootNode = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,<span style="color:#A020F0;">'root'</span>, <span style="color:#A020F0;">'File List'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% [matlab_work_path, '/fileListIcon.gif'],0);</span>
&nbsp;
<span style="color: #228B22;">% create two children with checkboxes</span>
cNode = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,<span style="color:#A020F0;">'unselected'</span>, <span style="color:#A020F0;">'File A'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% as icon is embedded here we set the icon via java, otherwise one could</span>
<span style="color: #228B22;">% use the uitreenode syntax uitreenode(value, string, icon, isLeaf) with</span>
<span style="color: #228B22;">% icon being a qualified pathname to an image to be used.</span>
cNode.<span style="">setIcon</span><span style="color: #080;">&#40;</span>javaImage_unchecked<span style="color: #080;">&#41;</span>;
rootNode.<span style="">add</span><span style="color: #080;">&#40;</span>cNode<span style="color: #080;">&#41;</span>;
&nbsp;
cNode = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,<span style="color:#A020F0;">'unselected'</span>, <span style="color:#A020F0;">'File B'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
cNode.<span style="">setIcon</span><span style="color: #080;">&#40;</span>javaImage_unchecked<span style="color: #080;">&#41;</span>;
rootNode.<span style="">add</span><span style="color: #080;">&#40;</span>cNode<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% set treeModel</span>
treeModel = DefaultTreeModel<span style="color: #080;">&#40;</span> rootNode <span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% create the tree</span>
tree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span><span style="color: #080;">&#41;</span>;
tree.<span style="">setModel</span><span style="color: #080;">&#40;</span> treeModel <span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% we often rely on the underlying java tree</span>
jtree = handle<span style="color: #080;">&#40;</span>tree.<span style="">getTree</span>,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% some layout</span>
<span style="color: #0000FF;">drawnow</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>tree, <span style="color:#A020F0;">'Units'</span>, <span style="color:#A020F0;">'normalized'</span>, <span style="color:#A020F0;">'position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">1</span> <span style="color: #33f;">0.5</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>tree, <span style="color:#A020F0;">'NodeSelectedCallback'</span>, @selected_cb <span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% make root the initially selected node</span>
tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> rootNode <span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% MousePressedCallback is not supported by the uitree, but by jtree</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jtree, <span style="color:#A020F0;">'MousePressedCallback'</span>, @mousePressedCallback<span style="color: #080;">&#41;</span>;
&nbsp;
  <span style="color: #228B22;">% Set the mouse-press callback</span>
  <span style="color: #0000FF;">function</span> mousePressedCallback<span style="color: #080;">&#40;</span>hTree, eventData<span style="color: #080;">&#41;</span> <span style="color: #228B22;">%,additionalVar)</span>
  <span style="color: #228B22;">% if eventData.isMetaDown % right-click is like a Meta-button</span>
  <span style="color: #228B22;">% if eventData.getClickCount==2 % how to detect double clicks</span>
&nbsp;
  <span style="color: #228B22;">% Get the clicked node</span>
    clickX = eventData.<span style="">getX</span>;
    clickY = eventData.<span style="">getY</span>;
    treePath = jtree.<span style="">getPathForLocation</span><span style="color: #080;">&#40;</span>clickX, clickY<span style="color: #080;">&#41;</span>;
    <span style="color: #228B22;">% check if a node was clicked</span>
    <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>treePath<span style="color: #080;">&#41;</span>
      <span style="color: #228B22;">% check if the checkbox was clicked</span>
      <span style="color: #0000FF;">if</span> clickX &lt;= <span style="color: #080;">&#40;</span>jtree.<span style="">getPathBounds</span><span style="color: #080;">&#40;</span>treePath<span style="color: #080;">&#41;</span>.<span style="">x</span>+iconWidth<span style="color: #080;">&#41;</span>
        node = treePath.<span style="">getLastPathComponent</span>;
        nodeValue = node.<span style="">getValue</span>;
        <span style="color: #228B22;">% as the value field is the selected/unselected flag,</span>
        <span style="color: #228B22;">% we can also use it to only act on nodes with these values</span>
        <span style="color: #0000FF;">switch</span> nodeValue
          <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'selected'</span>
            node.<span style="">setValue</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'unselected'</span><span style="color: #080;">&#41;</span>;
            node.<span style="">setIcon</span><span style="color: #080;">&#40;</span>javaImage_unchecked<span style="color: #080;">&#41;</span>;
            jtree.<span style="">treeDidChange</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
          <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'unselected'</span>
            node.<span style="">setValue</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'selected'</span><span style="color: #080;">&#41;</span>;
            node.<span style="">setIcon</span><span style="color: #080;">&#40;</span>javaImage_checked<span style="color: #080;">&#41;</span>;
            jtree.<span style="">treeDidChange</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
        <span style="color: #0000FF;">end</span>
      <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">end</span> <span style="color: #228B22;">% function mousePressedCallback</span>
&nbsp;
  <span style="color: #0000FF;">function</span> selected_cb<span style="color: #080;">&#40;</span> tree, ev <span style="color: #080;">&#41;</span>
    nodes = tree.<span style="">getSelectedNodes</span>;
    node = nodes<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">path</span> = node2path<span style="color: #080;">&#40;</span>node<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
&nbsp;
  <span style="color: #0000FF;">function</span> <span style="color: #0000FF;">path</span> = node2path<span style="color: #080;">&#40;</span>node<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">path</span> = node.<span style="">getPath</span>;
    <span style="color: #0000FF;">for</span> <span style="color: #33f;">i</span>=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">path</span><span style="color: #080;">&#41;</span>;
      p<span style="color: #080;">&#123;</span><span style="color: #33f;">i</span><span style="color: #080;">&#125;</span> = <span style="color: #0000FF;">char</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">path</span><span style="color: #080;">&#40;</span><span style="color: #33f;">i</span><span style="color: #080;">&#41;</span>.<span style="">getName</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>p<span style="color: #080;">&#41;</span> &gt; <span style="color: #33f;">1</span>
      <span style="color: #0000FF;">path</span> = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span>p<span style="color: #080;">&#123;</span><span style="color: #F0F;">:</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">else</span>
      <span style="color: #0000FF;">path</span> = p<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span>;
    <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">end</span>
&nbsp;
  <span style="color: #228B22;">% add node</span>
  <span style="color: #0000FF;">function</span> b1_cb<span style="color: #080;">&#40;</span> h, env <span style="color: #080;">&#41;</span>
    nodes = tree.<span style="">getSelectedNodes</span>;
    node = nodes<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
    parent = node;
    childNode = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,<span style="color:#A020F0;">'dummy'</span>, <span style="color:#A020F0;">'Child Node'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
    treeModel.<span style="">insertNodeInto</span><span style="color: #080;">&#40;</span>childNode,parent,parent.<span style="">getChildCount</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #228B22;">% expand to show added child</span>
    tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> childNode <span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #228B22;">% insure additional nodes are added to parent</span>
    tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> parent <span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
&nbsp;
  <span style="color: #228B22;">% remove node</span>
  <span style="color: #0000FF;">function</span> b2_cb<span style="color: #080;">&#40;</span> h, env <span style="color: #080;">&#41;</span>
    nodes = tree.<span style="">getSelectedNodes</span>;
    node = nodes<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">if</span> ~node.<span style="">isRoot</span>
      nP = node.<span style="">getPreviousSibling</span>;
      nN = node.<span style="">getNextSibling</span>;
      <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span> nN <span style="color: #080;">&#41;</span>
        tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> nN <span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">elseif</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span> nP <span style="color: #080;">&#41;</span>
        tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> nP <span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">else</span>
        tree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span> node.<span style="">getParent</span> <span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">end</span>
      treeModel.<span style="">removeNodeFromParent</span><span style="color: #080;">&#40;</span> node <span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span> <span style="color: #228B22;">% of main function treeExperiment6</span>
&nbsp;
  <span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#93;</span> = checkedIcon<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">I</span> = <span style="color: #0000FF;">uint8</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span>
        <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
         <span style="color: #33f;">1</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
     map = <span style="color: #080;">&#91;</span><span style="color: #33f;">0.023529</span>,<span style="color: #33f;">0.4902</span>,<span style="color: #33f;">0</span>;
            <span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>;
            <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
            <span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>;
            <span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>;
            <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
            <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
            <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;
  <span style="color: #0000FF;">end</span>
&nbsp;
  <span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span><span style="color: #0000FF;">I</span>,map<span style="color: #080;">&#93;</span> = uncheckedIcon<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
     <span style="color: #0000FF;">I</span> = <span style="color: #0000FF;">uint8</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span>
       <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">2</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span>;
        <span style="color: #33f;">1</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">3</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
     map = <span style="color: #F0F;">...</span>
      <span style="color: #080;">&#91;</span><span style="color: #33f;">0.023529</span>,<span style="color: #33f;">0.4902</span>,<span style="color: #33f;">0</span>;
       <span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>;
       <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
       <span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>;
       <span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>,<span style="color: #33f;">0.50196</span>;
       <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
       <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>;
       <span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;
  <span style="color: #0000FF;">end</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 369px"><img alt="uitree with custom checkbox icons" src="http://UndocumentedMatlab.com/images/uitree8.png" title="uitree with custom checkbox icons" width="359" height="283" /><p class="wp-caption-text">uitree with custom checkbox icons</p></div></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>.</p>
<p>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>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">import com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">checkboxtree</span>.*
jRoot = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Root'</span><span style="color: #080;">&#41;</span>;
l1a = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Letters'</span><span style="color: #080;">&#41;</span>; jRoot.<span style="">add</span><span style="color: #080;">&#40;</span>l1a<span style="color: #080;">&#41;</span>;
l1b = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Numbers'</span><span style="color: #080;">&#41;</span>; jRoot.<span style="">add</span><span style="color: #080;">&#40;</span>l1b<span style="color: #080;">&#41;</span>;
l2a = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'A'</span><span style="color: #080;">&#41;</span>; l1a.<span style="">add</span><span style="color: #080;">&#40;</span>l2a<span style="color: #080;">&#41;</span>;
l2b = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'b'</span><span style="color: #080;">&#41;</span>; l1a.<span style="">add</span><span style="color: #080;">&#40;</span>l2b<span style="color: #080;">&#41;</span>;
l2c = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'&lt;html&gt;&lt;b&gt;&amp;alpha;'</span><span style="color: #080;">&#41;</span>; l1a.<span style="">add</span><span style="color: #080;">&#40;</span>l2c<span style="color: #080;">&#41;</span>;
l2d = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'&lt;html&gt;&lt;i&gt;&amp;beta;'</span><span style="color: #080;">&#41;</span>; l1a.<span style="">add</span><span style="color: #080;">&#40;</span>l2d<span style="color: #080;">&#41;</span>;
l2e = DefaultCheckBoxNode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'3.1415'</span><span style="color: #080;">&#41;</span>; l1b.<span style="">add</span><span style="color: #080;">&#40;</span>l2e<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Present the standard MJTree:</span>
jTree = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJTree</span><span style="color: #080;">&#40;</span>jRoot<span style="color: #080;">&#41;</span>;
jScrollPane = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJScrollPane</span><span style="color: #080;">&#40;</span>jTree<span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>jComp,hc<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jScrollPane,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">120</span>,<span style="color: #33f;">110</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Now present the CheckBoxTree:</span>
jCheckBoxTree = CheckBoxTree<span style="color: #080;">&#40;</span>jTree.<span style="">getModel</span><span style="color: #080;">&#41;</span>;
jScrollPane = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJScrollPane</span><span style="color: #080;">&#40;</span>jCheckBoxTree<span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>jComp,hc<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jScrollPane,<span style="color: #080;">&#91;</span><span style="color: #33f;">150</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">120</span>,<span style="color: #33f;">110</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 321px"><img alt="a regular MJTree (left) and a CheckBoxTree (right)" src="http://UndocumentedMatlab.com/images/CheckBoxTree.png" title="a regular MJTree (left) and a CheckBoxTree (right)" width="311" height="218" /><p class="wp-caption-text">a regular MJTree (left) and a CheckBoxTree (right)</p></div></center></p>
<p>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.</p>
<p>This concludes my <i><b>uitree</b></i> mini-series. If you have any special customizations, please post a comment <a href="http://UndocumentedMatlab.com/blog/customizing-uitree-nodes-2/#respond">below</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Customizing uitree nodes &#8211; part 1</title>
		<link>http://undocumentedmatlab.com/blog/customizing-uitree-nodes/</link>
		<comments>http://undocumentedmatlab.com/blog/customizing-uitree-nodes/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 18:00:20 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Icons]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[uitools]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1835</guid>
		<description><![CDATA[This article describes how to customize specific nodes of Matlab GUI tree controls created using the undocumented uitree function

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>In my previous posts, I introduced the semi-documented <a target="_blank" href="http://UndocumentedMatlab.com/blog/uitree/"><i><b>uitree</b></i> function</a> that enables displaying data in a hierarchical (tree) control in Matlab GUI, and showed how it can be <a target="_blank" href="http://UndocumentedMatlab.com/blog/customizing-uitree/">customized</a>. Today, I will continue by describing how specific <i><b>uitree</b></i> nodes can be customized.</p>
<p>To start the discussion, let&#8217;s re-create last week&#8217;s simple <i><b>uitree</b></i>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Fruits</span>
fruits = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Fruits'</span>, <span style="color:#A020F0;">'Fruits'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Apple'</span>,  <span style="color:#A020F0;">'Apple'</span>,  <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Pear'</span>,   <span style="color:#A020F0;">'Pear'</span>,   <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Banana'</span>, <span style="color:#A020F0;">'Banana'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Orange'</span>, <span style="color:#A020F0;">'Orange'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Vegetables</span>
veggies = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Veggies'</span>, <span style="color:#A020F0;">'Vegetables'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Potato'</span>, <span style="color:#A020F0;">'Potato'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Tomato'</span>, <span style="color:#A020F0;">'Tomato'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Carrot'</span>, <span style="color:#A020F0;">'Carrot'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Root node</span>
root = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
root.<span style="">add</span><span style="color: #080;">&#40;</span>veggies<span style="color: #080;">&#41;</span>;
root.<span style="">add</span><span style="color: #080;">&#40;</span>fruits<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Tree</span>
<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">300</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">150</span>,<span style="color: #33f;">150</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
mtree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Root'</span>, root<span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 360px"><img alt="User-created tree" src="http://UndocumentedMatlab.com/images/uitree7a.png" title="User-created tree" width="158" height="232" /> &nbsp;&nbsp; <img alt="User-created tree" src="http://UndocumentedMatlab.com/images/uitree7b.png" title="User-created tree" width="158" height="232" /><p class="wp-caption-text">User-created tree</p></div></center></p>
<h3 id="labels">Labels</h3>
<p>Node labels (descriptions) can be set using their <strong>Name</strong> property (the second <i><b>uitreenode</b></i> data argument). Note that the horizontal space allotted for displaying the node name will not change until the node is collapsed or expanded. So, if the new name requires more than the existing space, it will be displayed as something like &#8220;abc…&#8221;, until the node is expanded or collapsed.</p>
<p>Node names share the same <a target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">HTML support feature</a> as all Java Swing labels. Therefore, we can specify font size/face/color, bold, italic, underline, super-/sub-script etc.:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">txt1 = <span style="color:#A020F0;">'&lt;html&gt;&lt;b&gt;&lt;u&gt;&lt;i&gt;abra&lt;/i&gt;&lt;/u&gt;'</span>;
txt2 = <span style="color:#A020F0;">'&lt;font color=&quot;red&quot;&gt;&lt;sup&gt;kadabra&lt;/html&gt;'</span>;
node.<span style="">setName</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>txt1,txt2<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 160px"><img alt="HTML-enriched tree nodes" src="http://UndocumentedMatlab.com/images/uitree2.jpg" title="HTML-enriched tree nodes" width="116" height="50" /><p class="wp-caption-text">HTML-enriched tree nodes</p></div></center></p>
<h3 id="icons">Icons</h3>
<p>Tree-node icons can be specified during node creation, as the third data argument to <i><b>uitreenode</b></i>, which accepts an icon-path (a string):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">iconPath = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/toolbox/matlab/icons/greenarrowicon.gif'</span><span style="color: #080;">&#41;</span>;
node = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,value,name,iconPath,isLeaf<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Tree node icons can also be created or modified programmatically in run-time, using Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/im2java.html">im2java</a> function. Icons can also be loaded from existing files as follows (real-life programs should check and possibly update jImage&#8217;s size to 16 pixels, before setting the node icon, otherwise the icon might get badly cropped; also note the tree-refreshing action):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jImage = java.<span style="">awt</span>.<span style="">Toolkit</span>.<span style="">getDefaultToolkit</span>.<span style="">createImage</span><span style="color: #080;">&#40;</span>iconPath<span style="color: #080;">&#41;</span>;
veggies.<span style="">setIcon</span><span style="color: #080;">&#40;</span>jImage<span style="color: #080;">&#41;</span>;
veggies.<span style="">setIcon</span><span style="color: #080;">&#40;</span>im2java<span style="color: #080;">&#40;</span><span style="color: #0000FF;">imread</span><span style="color: #080;">&#40;</span>iconPath<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative</span>
&nbsp;
<span style="color: #228B22;">% refresh the veggies node (and all its children)</span>
mtree.<span style="">reloadNode</span><span style="color: #080;">&#40;</span>veggies<span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 168px"><img alt="Setting node icon" src="http://UndocumentedMatlab.com/images/uitree7c.png" title="Setting node icon" width="158" height="232" /><p class="wp-caption-text">Setting node icon</p></div></center></p>
<h3 id="behavior">Behavior</h3>
<p>Nodes can be modified from leaf (non-expandable) to parent behavior (=expandable) by setting their <strong>LeafNode</strong> property (a related property is <strong>AllowsChildren</strong>):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>node,<span style="color:#A020F0;">'LeafNode'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% =expandable</span>
node.<span style="">setLeafNode</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative</span></pre></div></div>

<p>One of the questions I was <a target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-388">asked</a> was how to &#8220;disable&#8221; a specific tree node. One way would be to modify the tree&#8217;s <strong>ExpandFcn</strong> callback. Another way is to use a combination of HTML rendering and the node&#8217;s <strong>AllowsChildren</strong> property:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">label = <span style="color: #0000FF;">char</span><span style="color: #080;">&#40;</span>veggies.<span style="">getName</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">setName</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'&lt;html&gt;&lt;font color=&quot;gray&quot;&gt;'</span> label<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">setAllowsChildren</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
t.<span style="">reloadNode</span><span style="color: #080;">&#40;</span>veggies<span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 168px"><img alt="Disabled node" src="http://UndocumentedMatlab.com/images/uitree7d.png" title="Disabled node" width="158" height="232" /><p class="wp-caption-text">Disabled node</p></div></center></p>
<p>Another possible behavioral customization is <a target="_blank" href="http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/">adding a context-menu to a uitree</a>. We can set node-specific tooltips using similar means.</p>
<p>Answering a reader&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-uitree/#comment-15781">request</a> from last week, tree nodes icons can be used to present checkboxes, radio buttons and other similar node-specific controls. This can actually be done in several ways, that will be explored in next week&#8217;s article. </p>
<p>There are numerous other possible customizations &#8211; if readers are interested, perhaps I will describe some of them in future articles. If you have any special request, please post a comment <a href="http://undocumentedmatlab.com/blog/customizing-uitree-nodes/#respond">below</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/customizing-uitree-nodes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Customizing uitree</title>
		<link>http://undocumentedmatlab.com/blog/customizing-uitree/</link>
		<comments>http://undocumentedmatlab.com/blog/customizing-uitree/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 18:00:15 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<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[pure Matlab]]></category>
		<category><![CDATA[uitools]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1808</guid>
		<description><![CDATA[This article describes how to customize Matlab GUI tree controls created using the undocumented uitree function

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Last week, I introduced the semi-documented <a target="_blank" href="http://UndocumentedMatlab.com/blog/uitree/"><i><b>uitree</b></i> function</a> that enables displaying data in a hierarchical (tree) control in Matlab GUI.</p>
<p>Today, I will continue by describing how <i><b>uitree</b></i>s can be customized. </p>
<p>Note that although <i><b>uitree</b></i>s use Java objects internally, we can create and customize <i><b>uitree</b></i> using pure-Matlab code.</p>
<h3 id="creating">Creating non-standard tree types</h3>
<p>To start the discussion, let&#8217;s create a simple <i><b>uitree</b></i> whose <strong>Root</strong> node is not one of the automatically-processed types (disk folder, GUI handle, or Simulink model). There are two ways of creating such a tree: <em>active</em> and <em>reactive</em>:</p>
<h4 id="active">Actively building the tree</h4>
<p>In this method, we actively create nodes and attach them to parent nodes when the tree is first built. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Fruits</span>
fruits = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Fruits'</span>, <span style="color:#A020F0;">'Fruits'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Apple'</span>,  <span style="color:#A020F0;">'Apple'</span>,  <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Pear'</span>,   <span style="color:#A020F0;">'Pear'</span>,   <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Banana'</span>, <span style="color:#A020F0;">'Banana'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
fruits.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Orange'</span>, <span style="color:#A020F0;">'Orange'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Vegetables</span>
veggies = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Veggies'</span>, <span style="color:#A020F0;">'Vegetables'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Potato'</span>, <span style="color:#A020F0;">'Potato'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Tomato'</span>, <span style="color:#A020F0;">'Tomato'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
veggies.<span style="">add</span><span style="color: #080;">&#40;</span>uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Carrot'</span>, <span style="color:#A020F0;">'Carrot'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Root node</span>
root = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
root.<span style="">add</span><span style="color: #080;">&#40;</span>veggies<span style="color: #080;">&#41;</span>;
root.<span style="">add</span><span style="color: #080;">&#40;</span>fruits<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Tree</span>
<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">300</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">150</span>,<span style="color: #33f;">150</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
mtree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Root'</span>, root<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>The tree automatically display scrollbars if any of the presented tree-nodes requires more than the available tree space:</p>
<p><center><div class="wp-caption aligncenter" style="width: 360px"><img alt="User-created tree" src="http://UndocumentedMatlab.com/images/uitree7a.png" title="User-created tree" width="158" height="232" /> &nbsp;&nbsp; <img alt="User-created tree" src="http://UndocumentedMatlab.com/images/uitree7b.png" title="User-created tree" width="158" height="232" /><p class="wp-caption-text">User-created tree</p></div></center></p>
<h4 id="reactive">Reactively building the tree</h4>
<p>In this method, also called &#8220;lazy loading&#8221;, we only create child nodes as a reaction to their parent node&#8217;s expansion. This is the method given in <i><b>uitree</b></i>&#8217;s semi-documented help section. The tree will initially display only the root node, and additional tree-nodes will be created as needed when the root or any of its child nodes is expanded.</p>
<p>For example (note how the data model is passed as an extra parameter to the <strong>ExpandFcn</strong> callback):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create the data</span>
food.<span style="">veggies</span> = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Potato'</span>,<span style="color:#A020F0;">'Tomato'</span>,<span style="color:#A020F0;">'Carrot'</span><span style="color: #080;">&#125;</span>;
food.<span style="">fruits</span> = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Apple'</span>,<span style="color:#A020F0;">'Pear'</span>,<span style="color:#A020F0;">'Banana'</span>,<span style="color:#A020F0;">'Orange'</span><span style="color: #080;">&#125;</span>;
&nbsp;
<span style="color: #228B22;">% Create the tree with an ExpandFcn  callback</span>
root = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color:#A020F0;">'Food'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">300</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">150</span>,<span style="color: #33f;">150</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
mtree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Root'</span>,root, <span style="color:#A020F0;">'ExpandFcn'</span>,<span style="color: #080;">&#123;</span>@myExpandFcn,food<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% The following function should be added to Matlab's path:</span>
<span style="color: #0000FF;">function</span> nodes = myExpandfcn<span style="color: #080;">&#40;</span>tree, value, model<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF;">try</span>
    nodeIdx = <span style="color: #33f;">0</span>;
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>value,<span style="color:#A020F0;">'Food'</span><span style="color: #080;">&#41;</span>
      nodeNames = <span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span>model<span style="color: #080;">&#41;</span>;
      isLeaf = <span style="color: #0000FF;">false</span>;
    <span style="color: #0000FF;">else</span>
      nodeNames = model.<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span>;
      isLeaf = <span style="color: #0000FF;">false</span>;
    <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">for</span> nodeIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>nodeNames<span style="color: #080;">&#41;</span>
      nodeName = nodeNames<span style="color: #080;">&#123;</span>nodeIdx<span style="color: #080;">&#125;</span>;
      nodes<span style="color: #080;">&#40;</span>nodeIdx<span style="color: #080;">&#41;</span> = uitreenode<span style="color: #080;">&#40;</span>nodeName,nodeName,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,isLeaf<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">catch</span>
    <span style="color: #228B22;">% never mind...</span>
  <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>nodeIdx<span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> nodeIdx == <span style="color: #33f;">0</span>
      nodes = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>;
  <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<h3 id="resizing">Resizing the tree</h3>
<p><i><b>uitree</b></i>s are created with a default position of (0,0), a width of 200 (or less if the figure is narrower) and a height spanning the entire figure&#8217;s content area. This can easily be modified following the tree&#8217;s creation using its <b>Position</b> property:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">mtree = uitree<span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
mtree.<span style="">Position</span> = <span style="color: #080;">&#91;</span><span style="color: #33f;">100</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">50</span>,<span style="color: #33f;">150</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">% modify position &amp; size</span>
mtree.<span style="">Position</span><span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span> = <span style="color: #33f;">100</span>;  <span style="color: #228B22;">% limit tree height to 100 pixels</span></pre></div></div>

<h3 id="java">Java-based customizations</h3>
<p>Today&#8217;s article used pure Matlab code (or more precisely, Java code wrapped in pure Matlab). Many additional customizations are available at the JTree-level. The underlying jtree handle can easily be retrieved:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jtree = mtree.<span style="">getTree</span>;
jtree = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>mtree, <span style="color:#A020F0;">'tree'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative</span></pre></div></div>

<p>As an example customization that uses jtree, consider one of my earliest articles on this website: <a target="_blank" href="http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/">Adding a context-menu to a uitree</a>.</p>
<p>Interested readers might also benefit from looking at the tree manipulations that I have programmed in my <a target="_blank" href="http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/">FindJObj</a> utility.</p>
<p>Next week&#8217;s article will conclude my <i><b>uitree</b></i> mini-series by describing how specific tree nodes can be customized. If you have any special customization request, please post a comment <a href="http://undocumentedmatlab.com/blog/customizing-uitree/#respond">below</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/customizing-uitree/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>uitree</title>
		<link>http://undocumentedmatlab.com/blog/uitree/</link>
		<comments>http://undocumentedmatlab.com/blog/uitree/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 18:00:40 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[pure Matlab]]></category>
		<category><![CDATA[uitools]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1801</guid>
		<description><![CDATA[This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Can you guess which built-in Matlab function is the top search-term on <a target="_blank" href="http://UndocumentedMatlab.com/">UndocumentedMatlab.com</a> and yet <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/search_results?dur=all&#038;search_string=uitree&#038;sort=replies_dn">one of the least discussed topic on the CSSM forum</a>? </p>
<p>The answer is <i><b>uitree</b></i> &#8211; Matlab&#8217;s built-in function for displaying data in a hierarchical (tree) GUI component. <i><b>uitree</b></i> has been included in all Matlab 7 releases, but has never been officially supported. Like most other <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/uitools/">uitools</a> in the %matlabroot%/toolbox/matlab/uitools/ folder, <i><b>uitree</b></i> and its companion <i><b>uitreenode</b></i> are <a target="_blank" href="http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a>, meaning that they have no support or doc-page, but do have readable help sections within their m-files. In our case, edit the uitree.m and uitreenode.m files to see their help section. </p>
<p>Note the following comment within %matlabroot%/toolbox/local/hgrc.m, which implies that <i><b>uitree</b></i> may soon become fully supported, although its interface might change somewhat (as was the case when <i><b>uitable</b></i> became supported in R2008a):<br />
<q>Temporarily turn off old uitree and uitreenode deprecated function warning… When we introduce the new documented uitree to replace the old undocumented uitree …</q></p>
<p>Like most other uitools (e.g. <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uitable.html"><i><b>uitable</b></i></a> and <a target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a>), <i><b>uitree</b></i> is based on an underlying Java component, which ultimately extends Swing&#8217;s standard <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">JTree</a>. <i><b>uitree</b></i> sets up a scrollable JTree on-screen without the hassle of setting up a <a target="_blank" rel="nofollow" href="http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html">scrollable viewport</a> and other similar nuts and bolts. In fact, <strong><u>you don&#8217;t need to know any Java</u></strong> to use <i><b>uitree</b></i> (although knowing JTree can greatly help you customize it) &#8211; <i><b>uitree</b></i>s can be manipulated using pure Matlab code, as shall be seen below. </p>
<p><i><b>uitree</b></i> accepts an optional figure handle followed by P-V (property-value) pairs. Settable properties are <strong>Root, ExpandFcn, SelectionChangeFcn, Position</strong> (also <strong>Parent</strong>, but read on). As in <i><b>uitab</b></i>, a &#8216;v0&#8242; input argument may be necessary to suppress a warning message. Note that <i><b>uitree</b></i>s are always created as a direct child of the containing figure, ignoring creation-time <strong>Parent</strong> values. However, the <strong>Parent</strong> property can be modified following the tree&#8217;s creation:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #080;">&#91;</span>mtree, container<span style="color: #080;">&#93;</span> = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'Root'</span>,<span style="color:#A020F0;">'C:\'</span>, <span style="color:#A020F0;">'Parent'</span>,hPanel<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% Parent is ignored</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>container, <span style="color:#A020F0;">'Parent'</span>, hPanel<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% fix the uitree Parent</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 302px"><img alt="A simple uitree" src="http://UndocumentedMatlab.com/images/uitree1.png" title="A simple uitree" width="292" height="299" /><p class="wp-caption-text">A simple uitree</p></div></center></p>
<p><i><b>uitree</b></i> returns two arguments: a handle to the created tree (a Java object wrapped within a Matlab handle) and an entirely-undocumented second optional argument holding a handle to the Matlab GUI container of the created tree. These two arguments are exactly the two arguments returned from the <i><b>javacomponent</b></i> function that I described <a target="_blank" href="http://undocumentedmatlab.com/blog/javacomponent/">last week</a>. </p>
<h3 id="uitreenode"><i><b>uitreenode</b></i></h3>
<p><i><b>uitree</b></i> automatically understands <strong>Root</strong> objects of type Handle Graphics, Simulink model or char string (interpreted as a file-system folder name). Other <strong>Root</strong> types require setting dedicated <strong>ExpandFcn, SelectionChangeFcn</strong> Matlab callbacks (see <i><b>uitree</b></i>&#8217;s help section or below for examples).</p>
<p>If we need to create a custom tree hierarchy (i.e., our root node is not an HG object, Simulink model or folder name), then we need to use the semi-documented <i><b>uitreenode</b></i> function as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">node = uitreenode<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>,handle<span style="color: #080;">&#40;</span>mtree<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'my root'</span>,<span style="color:#A020F0;">'c:\root.gif'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
mtree.<span style="">setRoot</span><span style="color: #080;">&#40;</span>node<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>mtree,<span style="color:#A020F0;">'Root'</span>,node<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% alternative to mtree.setRoot()</span></pre></div></div>

<p><i><b>uitreenode</b></i> accepts 4 arguments: a string or handle value (the node&#8217;s &#8220;internal&#8221; value), a string description (shown next to the node&#8217;s icon), an icon filename ([] will result in an icon assigned based on the node value), and a flag indicating whether the node is a leaf (no children) or not.</p>
<p><i><b>uitreenode</b></i> returns a node object, which is little more than a Matlab handle wrapper for a Java Swing <a target="_blank" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/tree/DefaultMutableTreeNode.html">DefaultMutableTreeNode</a>.</p>
<h3 id="Manipulation">Node manipulation</h3>
<p>Nodes can be added, moved or removed by node methods: node.<em>add(anotherNode)</em> adds <em>anotherNode</em> to the end of this node’s children list (possibly detaching it from its previous parent); node.<em>insert(anotherNode,index)</em> does the same but inserts <em>anotherNode</em> at a specific child index, rather than at the end; node.<em>clone()</em> makes a duplicate of this node that can then be added to another node; node.<em>remove(index)</em> and node.<em>remove(node)</em> remove a specific node whereas node.<em>removeFromParent()</em> removes this node; node.<em>removeAllChildren()</em> removes all children, if any, of this node.</p>
<p>Nodes can also be added and removed at the tree level: mtree.<em>add(parent,nodes)</em> allows adding a list of nodes to a parent node and mtree.<em>remove(nodes)</em> removes the specified nodes.</p>
<p>In order to programmatically collapse and expand nodes, use mtree.<em>collapse(node)</em> and mtree.<em>expand(node)</em>.</p>
<p>Nodes can be programmatically selected using mtree.<em>setSelectedNode(node)</em>. Multiple nodes may be selected using mtree.<em>setSelectedNodes</em>, if an earlier call to mtree.<em>setMultipleSelectionEnabled(true)</em> was made (default is multiple-selection disabled):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">mtree.<span style="">setSelectedNode</span><span style="color: #080;">&#40;</span>root<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% root is a node</span>
mtree.<span style="">setSelectedNodes</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>root,node1,node2<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% select 3 nodes</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 208px"><img alt="programmatically selecting multiple tree nodes" src="http://UndocumentedMatlab.com/images/uitree2a.png" title="programmatically selecting multiple tree nodes" width="198" height="215" /><p class="wp-caption-text">programmatically selecting multiple tree nodes</p></div></center></p>
<p>The currently-selected node(s) can be accessed using mtree.<em>getSelectedNodes</em>. Node selection callbacks often require knowledge of the currently selected rows:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Tree set up</span>
mtree = uitree<span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span>, <span style="color:#A020F0;">'SelectionChangeFcn'</span>,@mySelectFcn<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>mtree, <span style="color:#A020F0;">'SelectionChangeFcn'</span>,@mySelectFcn<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% an alternative</span>
&nbsp;
<span style="color: #228B22;">% The tree-node selection callback</span>
<span style="color: #0000FF;">function</span> nodes = mySelectFcn<span style="color: #080;">&#40;</span>tree, value<span style="color: #080;">&#41;</span>
    selectedNodes = tree.<span style="">getSelectedNodes</span>;
    <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>selectedNodes<span style="color: #080;">&#41;</span>
        <span style="color: #228B22;">% ...</span>
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% mySelectFcn</span></pre></div></div>

<p>Interested readers might also benefit from looking at the tree manipulations that I have programmed in my <a target="_blank" href="http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/">FindJObj</a> utility.</p>
<p>Next week&#8217;s article will show how <i><b>uitree</b></i>s can be customized. There are numerous possible customizations, including icons, labels, appearance, and behavior. So if you have any special request, please post a comment <a href="http://undocumentedmatlab.com/blog/uitree/#respond">below</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/customizing-uitree/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-uitree-nodes-2/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/adding-context-menu-to-uitree/' rel='bookmark' title='Permanent Link: Adding a context-menu to a uitree'>Adding a context-menu to a uitree</a> <small>uitree is an undocumented Matlab function, which does not easily enable setting a context-menu. Here's how to do it....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/uitree/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The javacomponent function</title>
		<link>http://undocumentedmatlab.com/blog/javacomponent/</link>
		<comments>http://undocumentedmatlab.com/blog/javacomponent/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 18:00:59 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></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[UI controls]]></category>
		<category><![CDATA[schema.prop]]></category>
		<category><![CDATA[uicontrol]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1793</guid>
		<description><![CDATA[Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='Permanent Link: ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Permanent Link: Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Permanent Link: Inactive Control Tooltips &#038; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>In this blog I have often showed how using Java components can significantly improve Matlab GUI. Here is a simple reminder:</p>
<p><center><div class="wp-caption aligncenter" style="width: 460px"><a target="_blank" href="http://UndocumentedMatlab.com/images/uicomponent.png"><img alt="sample Java components integrated in Matlab figure window (click for details)" src="http://UndocumentedMatlab.com/images/uicomponent.png" title="sample Java components integrated in Matlab figure window (click for details)" width="450" height="354" /></a><p class="wp-caption-text">sample Java components integrated in Matlab figure window (click for details)</p></div></center></p>
<p>Matlab is highly integrated with Java, and Java classes can seamlessly be accessed from Matlab. However, displaying Java GUI objects, as opposed to using computational (non-displayable) Java classes, requires using Matlab&#8217;s built-in <i><b>javacomponent</b></i> function. I have often used this function in past articles here, and today I would like to describe it in more detail.</p>
<p><i><b>javacomponent</b></i>, available since R14 (Matlab 7.0), is yet another <a target="_blank" href="http://UndocumentedMatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> built-in function. This means that the function is explained in a comment within the function (which can be seen via the <i><b>edit</b>(&#8216;javacomponent&#8217;)</i> command), but nonetheless does not have official help or doc pages. It is an unsupported function originally intended only for internal Matlab use (which of course doesn&#8217;t mean we can&#8217;t use it).</p>
<p><i><b>javacomponent</b></i> accepts a component class name (a string) or a reference to a previously-created component object, an optional pixel position parameter (default=[20,20,60,20], just like <i><b>uicontrol</b></i>; may also contain the strings &#8216;North&#8217;, &#8216;South&#8217;, &#8216;East&#8217; or &#8216;West&#8217;), and an optional parent container handle  (defaults to the current figure). <i><b>javacomponent</b></i> then adds the requested component as a child of the requested parent container and wraps it in a Matlab Handle-Graphics (HG) container. <i><b>javacomponent</b></i> returns two handles: the Matlab HG container handle and a reference (handle) to the Java component. Here are some sample invocation formats:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #080;">&#91;</span>jButton, hButton<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JButton'</span><span style="color: #080;">&#41;</span>
hButton =
	javahandle_withcallbacks.<span style="">javax</span>.<span style="">swing</span>.<span style="">JButton</span>
jButton =
          <span style="color: #33f;">158.002197265625</span>
&nbsp;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JButton'</span>,<span style="color:#A020F0;">'North'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span>javax.<span style="">swing</span>.<span style="">JButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click me!'</span><span style="color: #080;">&#41;</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">50</span>,<span style="color: #33f;">40</span>,<span style="color: #33f;">80</span>,<span style="color: #33f;">30</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span>javax.<span style="">swing</span>.<span style="">JButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click me!'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'East'</span>,hFig<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Note the difference between Java object creation and <i><b>javacomponent</b></i>: A pre-created Java object only resides in JVM (Java Virtual Machine) memory, not onscreen, until <i><b>javacomponent</b></i> is called to display it. <i><b>javacomponent</b></i> only creates objects when a class name (string) parameter is passed to it, as a convenience service to programmers. In practice, it is better to separate these two actions: create the Java object separately, and then pass the object&#8217;s reference handle to <i><b>javacomponent</b></i> for display. This enables easier error-trapping if the Java object cannot be created or fails to initialize, before attempting to display the object:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create and initialize a JScrollBar object</span>
<span style="color: #0000FF;">try</span>
   jScrollbar = javaObjectEDT<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JScrollBar'</span><span style="color: #080;">&#41;</span>;
   jScrollbar.<span style="">setOrientation</span><span style="color: #080;">&#40;</span>jScrollbar.<span style="">HORIZONTAL</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Cannot create Java-based scroll-bar!'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
<span style="color: #228B22;">% Display the object onscreen</span>
<span style="color: #0000FF;">try</span>
   javacomponent<span style="color: #080;">&#40;</span>jScrollbar,<span style="color:#A020F0;">'South'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Cannot display Java-base scroll-bar!'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>Note that Java GUI object should always use the EDT (Event Dispatch Thread). The reasons for this were outlined in the recent <a target="_blank" href="http://UndocumentedMatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/">Matlab-EDT article</a>. For this reason, the JScrollBar is created using the built-in <i><b>javaObjectEDT</b></i> function, which exists since R2008a and became documented/supported in R2009a.</p>
<p><i><b>javacomponent</b></i> accepts parent handles that are figures, toolbars, <i><b>uipanel</b></i>s or <a target="_blank" href="http://UndocumentedMatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/"><i><b>uicontainer</b></i>s</a>.  Unfortunately, frames are not <i><b>uicontainer</b></i>s and therefore cannot be used as <i><b>javacomponent</b></i> parents. <b><u>Addendum Aug 6 2010</u></b>: I made an incorrect statement in the original post here regarding <i><b>uipanel</b></i>s, which has now been removed. I thank the reader who pointed this out to me.</p>
<p>Once the component has been created, even before it has been placed onscreen, it can be manipulated just like any other Java object. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jButton.<span style="">setText</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click again!'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or: set(jButton,'text','…')</span></pre></div></div>

<p>The component can also be manipulated to some extent via its HG container, which is of a special Matlab type (class) called hgjavacomponent. This includes getting/setting the component position, position units, visibility, resizing callback, tag, <b>UserData</b> etc:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">0.2</span>,<span style="color: #33f;">0.3</span>,<span style="color: #33f;">0.1</span>,<span style="color: #33f;">0.05</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%note: on/off, not true/false as in Java</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'ResizeFcn'</span>,<span style="color: #080;">&#123;</span>@resizeCallbackFunc,param1,param2<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>When adding Java components which are container classes (descendants of <a target="_blank" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html">java.awt.Container</a>), it is important to remember that only other Java components can be added to these containers. Matlab objects such as axes (for plots or images) and <i><b>uicontrol</b></i>s cannot be added since they do not have a Container wrapper.  Therefore, feel free to use these Java containers as long as their contained GUI is limited to Java components (JButton, JComboBox etc.). This limitation is very annoying – it would be very useful to be able to place Matlab axes or <i><b>uicontrol</b></i>s within a JTabbedPane or JSplitPane. Instead, we need to rely on Matlab-based workarounds (<a target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23073-uisplitpane"><i><b>uisplitpane</b></i></a>) which are cumbersome compared to their Java counterparts.</p>
<p><i><b>javacomponent</b></i> can be used to place not only Swing components but also Swing-extended components onscreen. Matlab itself almost never uses Swing components as-is, instead preferring to use MathWorks-derived extensions of these components, generally in the com.mathworks.mwswing or com.mathworks.widgets packages. These packages and their classes are all in the static Java classpath and are therefore automatically available for use by Matlab programmers.</p>
<p>Just like Matlab components, <i><b>javacomponent</b></i> can also display third-party or your own Swing-derived components. There are quite a few online sources  for Swing components that can easily be incorporated in your Matlab application. Simply download the relevant class files, add them to your static (via classpath.txt) or dynamic (via <i><b>javaaddpath</b></i>) Java classpath, use <i><b>javacomponent</b></i> to display them, then use their reference handle to manipulate their appearance and behavior.</p>
<p><i><b>javacomponent</b></i>, useful as it is, has several limitations. In its string variant (classname) it requires a fully-qualified classname that is not inferred automatically. It also has a different parameters format than <i><b>uicontrol</b></i>, which may confuse users. <i><b>javacomponent</b></i> also cannot display <a target="_blank" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html">java.awt.Window</a> components. Finally, it returns two handles – one is a <i><b>handle</b>()</i> reference of the Java object; the second an HG handle (a double numeric value) of the automatically-created HG container – <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/172873">users are often confused</a> as to which property should be set on which of these handles. </p>
<p>To overcome these limitations, I created <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14583-UIComponent"><i><b>UIComponent</b></i></a> – a utility that merges <i><b>uicontrol</b></i> and <i><b>javacomponent</b></i>, available for download on the File Exchange.  It accepts all <i><b>uicontrol</b></i> parameters and styles, as well as any other displayable Java (Swing/AWT) class. <i><b>uicontrol</b></i>&#8217;s calling syntax was preserved for full backwards compatibility. <i><b>uicomponent</b></i> uses the built-in <i><b>uicontrol</b></i> whenever possible (for standard Matlab styles), and <i><b>javacomponent</b></i> for all other Java classes. </p>
<p><i><b>uicomponent</b></i> returns the same two handles that <i><b>javacomponent</b></i> returns (namely, a Java reference handle and a numeric HG handle), modified to include each other&#8217;s properties and handles (yet another undocumented trick that merits a dedicated article). Here are some examples (more can be found in <i><b>uicomponent</b></i>&#8217;s help comment):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">'hello'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% a regular uicontrol</span>
uicomponent<span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">'hello'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% specify parent</span>
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'jspinner'</span>,<span style="color:#A020F0;">'value'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>;
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'javax.swing.jslider'</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'myObj'</span><span style="color: #080;">&#41;</span>; 
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'JComboBox'</span>,<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span>,<span style="color: #0000FF;">pi</span>,<span style="color:#A020F0;">'text'</span><span style="color: #080;">&#125;</span>,<span style="color:#A020F0;">'editable'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Another File Exchange submission which aims to tackle some of <i><b>javacomponent</b></i>&#8217;s limitations is Malcolm Lidierth&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15580"><i><b>JCONTROL</b></i></a>. <i><b>jcontrol</b></i> uses Matlab&#8217;s new object-oriented class approach and has the benefit of returning just a single handle object, which aggregates the handles for both HG container and the contained Java object.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='Permanent Link: ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Permanent Link: Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Permanent Link: Inactive Control Tooltips &#038; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/javacomponent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>COM/ActiveX tips &amp; tricks</title>
		<link>http://undocumentedmatlab.com/blog/com-activex-tips/</link>
		<comments>http://undocumentedmatlab.com/blog/com-activex-tips/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 08:43:26 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1781</guid>
		<description><![CDATA[This article describes several little-known tips useful for COM / ActiveX programming in Matlab

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='Permanent Link: ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/spy-easter-egg/' rel='bookmark' title='Permanent Link: Spy Easter egg'>Spy Easter egg</a> <small>The built-in Matlab function spy has an undocumented feature (Easter egg) when it is called with no input arguments....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='Permanent Link: tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Component_Object_Model">COM</a>/<a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/ActiveX">ActiveX</a> interface has been supported and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brd4at8.html">well-documented</a> for many releases. However, there are still some aspects that are either not detailed, or that escape the casual documentation reader.</p>
<h3 id="Collections">Accessing collection items</h3>
<p>COM <i>collections</i> is a COM interface for sets of similar objects such as the worksheets in an Excel file or the images in a PowerPoint document. The items in a collection can be accessed using a numeric index (starting at 1) or the item&#8217;s string name.</p>
<p>The &#8220;normal&#8221; way to access collection items is using the <i>Item()</i> method that accepts a numeric index or the item&#8217;s name (a string).</p>
<p>Since collections are so common, Microsoft devised a short-cut of passing the parameter directly to the collection. For example, in our Excel VB code, instead of using <i>Worksheets.Item(2)</i> or <i>Worksheets.Item(&#8216;Sheet2&#8242;)</i>, we could write <i>Worksheets(2)</i> or <i>Worksheets(&#8216;Sheet2&#8242;)</i>. This shortcut is so common that the &#8220;normal&#8221; way of using <i>Item()</i> is rarely seen.</p>
<p>Unfortunately, Matlab&#8217;s implementation of the COM interface does not recognize this shortcut. Instead, we must use the more verbose way of using the <i>Item()</i>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Invalid - shortcut is not recognized by Matlab</span>
&gt;&gt; hSheet = hWorkbook.<span style="">Worksheets</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
??? Index exceeds matrix dimensions
&nbsp;
<span style="color: #228B22;">% Valid</span>
&gt;&gt; hSheet = hWorkbook.<span style="">Worksheets</span>.<span style="">Item</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
&gt;&gt; hSheet = hWorkbook.<span style="">Worksheets</span>.<span style="">Item</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Sheet2'</span><span style="color: #080;">&#41;</span>
hSheet =
	Interface.<span style="">Interface</span>.<span style="">Microsoft_Excel_11</span>.0_Object_Library._Worksheet</pre></div></div>

<p>Note that the dot-notation used above only works on recent Matlab 7 releases. Earlier releases (for example, Matlab 6.0 R12) have bugs that prevent it from functioning properly. The workaround is to use the following even-more-verbose way, which work on all Matlab releases:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hSheet = invoke<span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hWorkbook,<span style="color:#A020F0;">'Worksheets'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Item'</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Matlab&#8217;s documentation actually has a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f27433.html#f27442">short section</a> describing the valid way to access COM collection. IMHO, a special warning about the invalid but widely-used short-cut would have been useful. In any case, the issue of accessing collection items has often appeared on CSSM (for example, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/286930">here</a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/286988">here</a>), so I guess many programmers have overlooked this.</p>
<h3 id="Enumerations">Using enumerated values</h3>
<p>When setting COM property values, Matlab supports some enumerated (constant) values but not all (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f89715.html#f107980">read here</a>). In practice, this can be very frustrating since the VB code and documentation almost always refers to the enumerated values only. Without the ability to set enumeration values, some properties become unusable in Matlab.</p>
<p>Well, not really. There&#8217;s a workaround: Since every enumerated COM value hides a numeric value, we can pass the numeric values rather than the enumerated (string) value when setting such properties. The numeric values are seldom documented, but can often be easily found online (use Google!). Quite often, they appear in C header-files that #define the enumerated values as pre-processor items with the required numeric value. For example, the numeric value for xlXYScatterLines is <a target="_blank" rel="nofollow" href="http://www.google.com/search?q=%22define+xlXYScatterLines%22">easily found</a> to be 74.</p>
<p>Some of the enumerated constants are harder to find in this manner. You can use one of the following resources to search for your requested constant: <a target="_blank" rel="nofollow" href="http://techsupt.winbatch.com/ts/T000001033005F9.html">Excel</a>, <a target="_blank" rel="nofollow" href="http://www.wizardwrx.com/CommonTypelibs/O2000_MSPPT9.CSV">PowerPoint</a> (or <a target="_blank" rel="nofollow" href="http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/Constants+PPCONST.txt">here</a>), <a target="_blank" rel="nofollow" href="http://techsupt.winbatch.com/ts/T000001033F49.html">OLE/Office</a> (includes Word, Access and Internet Explorer), and an <a target="_blank" rel="nofollow" href="http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP//Constants">even larger list</a>.</p>
<p>Again, old Matlab versions have problems understanding string enumerations, but the numeric values are always accepted and so are backward-compatible. If your application needs to support old Matlab versions, always use the numeric values (add a comment with the enumerated name, for maintainability).</p>
<h3 id="Office2010">Office 2010</h3>
<p>Microsoft Office 2010 has apparently changed its COM interface, so accessing it from Matlab cannot easily be done. Luckily, Samuel Foucher has posted a workaround to this problem <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/287717#766303">on CSSM yesterday</a>. The trick is basically to have both an older Office and Office 2010 installed at the same time. As Samuel notes, &#8220;<i>This is far from an optimal solution but it seems to work so far</i>&#8220;. </p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='Permanent Link: ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/spy-easter-egg/' rel='bookmark' title='Permanent Link: Spy Easter egg'>Spy Easter egg</a> <small>The built-in Matlab function spy has an undocumented feature (Easter egg) when it is called with no input arguments....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='Permanent Link: tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/com-activex-tips/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Matlab DDE support</title>
		<link>http://undocumentedmatlab.com/blog/matlab-dde-support/</link>
		<comments>http://undocumentedmatlab.com/blog/matlab-dde-support/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 10:00:00 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[DDE]]></category>
		<category><![CDATA[pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1756</guid>
		<description><![CDATA[Windows DDE is an unsupported and undocumented feature of Matlab, that can be used to improve the work-flow in the Windows environment

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/' rel='bookmark' title='Permanent Link: HTML support in Matlab uicomponents'>HTML support in Matlab uicomponents</a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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>
<li><a href='http://undocumentedmatlab.com/blog/setprompt-setting-matlab-desktop-prompt/' rel='bookmark' title='Permanent Link: setPrompt &#8211; Setting the Matlab Desktop prompt'>setPrompt &#8211; Setting the Matlab Desktop prompt</a> <small>The Matlab Desktop's Command-Window prompt can easily be modified using some undocumented features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/' rel='bookmark' title='Permanent Link: Matlab layout managers: uicontainer and relatives'>Matlab layout managers: uicontainer and relatives</a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Dynamic_Data_Exchange">Windows DDE</a> was a 1990&#8217;s technology used to transfer control between Windows applications. DDE was fully supported and documented in old Matlab releases (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk_r13/help/techdoc/matlab_external/ch07cl21.html">R13</a>, <a target="_blank" rel="nofollow" href="http://www.system.nada.kth.se/unix/software/matlab/Release_14.1/techdoc/matlab_external/ch8_co28.html">R14</a>). DDE is no longer documented in Matlab, although it apparently still works. In fact, Matlab <a target="_blank" rel="nofollow" href="http://www.system.nada.kth.se/unix/software/matlab/Release_14.1/techdoc/matlab_external/ch8_co28.html">says</a>:<br />
<q>As of MATLAB version 5.1, all development work for the DDE Server and Client has been stopped and no further development will be done. The MathWorks strongly recommends that you migrate to the MATLAB interface to COM technology that is documented.</q></p>
<p>In the past decade, DDE has been superseded by newer Windows technologies deriving from <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Component_Object_Model">COM</a>, which is supported by Matlab. However, DDE is still used for some Windows infrastructure functions such as cut/copy/paste (CCP) and the Windows Shell file association. Today&#8217;s article, based on information given to me by Martin H&ouml;cker, a reader of this blog, uses this fact to interface the Windows Explorer with Matlab.</p>
<p>Martin works on an experiment that outputs a large number of small data files that have a &#8220;THe&#8221; extension. He wrote a Matlab script that parses and plots the data files individually. This script is called &#8220;THePlotter.m&#8221; and is on the Matlab path. But calling this script with the command &#8220;THePlotter(&#8216;D:\Data\somedata.THe&#8217;)&#8221; in Matlab&#8217;s console is tedious, especially if we need to check hundreds of files.</p>
<p>Since all data files have the same &#8220;.THe&#8221; extension, Martin associated this file type with Matlab so double-clicking any file in Explorer will plot the data in Matlab. It is very easy to set this up using DDE:</p>
<ol>
<li>associate the &#8220;.THe&#8221; file type with Matlab as shown below (note: use the MATLAB.exe file in the /bin/win32 or /bin/win64 subfolder). Now Matlab will generate an error for a double-click on the file, but we don&#8217;t care.<br />
<center><div class="wp-caption aligncenter" style="width: 340px"><a target="_blank" href="http://UndocumentedMatlab.com/images/DDE_Explorer_Associate.png"><img alt="Associating an extension with Matlab (click for details)" src="http://UndocumentedMatlab.com/images/DDE_Explorer_Associate.png" title="Associating an extension with Matlab (click for details)" width="330" height="439" /></a><p class="wp-caption-text">Associating an extension with Matlab (click for details)</p></div></center></li>
<li>in Windows Explorer, click on Tools / Folder Options / File Types</li>
<li>select the &#8220;.THe&#8221; extension and click &#8220;Advanced&#8221;<br />
<center><div class="wp-caption aligncenter" style="width: 410px"><a target="_blank" href="http://UndocumentedMatlab.com/images/DDE_Explorer_Edit.png"><img alt="Editing the file association details" src="http://UndocumentedMatlab.com/images/DDE_Explorer_Edit.png" title="Editing the file association details" width="400" height="328" /></a><p class="wp-caption-text">Editing the file association details</p></div></center></li>
<li>set this to be the default action upon mouse double-click or keyboard ENTER</li>
<li>select the &#8220;open&#8221; action, and click &#8220;Edit&#8230;&#8221;</li>
<li>rename the action &#8220;plot&#8221; (renaming is optional) and click the &#8220;Use DDE&#8221; checkbox</li>
<li>enter the DDE information as seen below:</li>
</ol>
<p><center><div class="wp-caption aligncenter" style="width: 460px"><a target="_blank" href="http://UndocumentedMatlab.com/images/DDE_Explorer_Settings.png"><img alt="Windows Explorer settings (click for details)" src="http://UndocumentedMatlab.com/images/DDE_Explorer_Settings.png" title="Windows Explorer settings (click for details)" width="450" height="233" /></a><p class="wp-caption-text">Windows Explorer settings (click for details)</p></div></center></p>
<p>It is even possible to have several &#8220;actions&#8221; for the file: Martin has &#8220;Plot&#8221;, and &#8220;Add to plot&#8221;, which allows plotting multiple files at once by simply choosing &#8220;Add to plot&#8221; with a right click in Windows Explorer:<br />
<center><div class="wp-caption aligncenter" style="width: 336px"><a target="_blank" href="http://UndocumentedMatlab.com/images/DDE_Explorer_Use.png"><img alt="Windows Explorer use (click for details)" src="http://UndocumentedMatlab.com/images/DDE_Explorer_Use.png" title="Windows Explorer use (click for details)" width="326" height="85" /></a><p class="wp-caption-text">Windows Explorer use (click for details)</p></div></center></p>
<p>Behind the scenes, all this is simply a GUI wrapper for adding/modifying the Windows Registry:<br />
<center><div class="wp-caption aligncenter" style="width: 442px"><img alt="Registry entry for the Shell file association" src="http://UndocumentedMatlab.com/images/DDE_Registry.png" title="Registry entry for the Shell file association" width="432" height="258" /><p class="wp-caption-text">Registry entry for the Shell file association</p></div></center></p>
<p>Note that despite some information in the R13/R14 documentation, we do not need to run Matlab with the /Automation startup flag (or any other special modification for that matter), at least in recent Matlab releases.</p>
<p>The biggest advantage of using DDE: It does not open up a new instance of Matlab whenever you click on a file. This saves an incredible amount of start-up time.</p>
<p>One thing we cannot do, is to pass parameter/value pairs to the &#8220;THePlotter&#8221; function. The problem possibly lies in the way that Matlab parses the DDE commands &#8211; the parameter is enclosed by quotes, and Matlab seems to turn these quotes into double-quotes, and then chokes on itself&#8230;</p>
<p>Have you found another neat trick to enhance your work-flow? If so, please share it in the <a href="http://undocumentedmatlab.com/blog/matlab-dde-support/#respond">comments</a> section below, or <a href="mailto:%20altmany%20@gmail.com?subject=Undocumented%20Matlab&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Undocumented Matlab&amp;body=Hi Yair, '); return false;">send me an email</a></p>
<p>p.s.: Readers who are interested in using Matlab&#8217;s DDE functionality programmatically, are welcome to read and use the following semi-documented built-in functions: <i><b>ddeadv, ddeexec, ddeinit, ddepoke, ddereq, ddeterm, ddeunadv</b></i>. These functions have a readable help section, but no doc page nor official support.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/' rel='bookmark' title='Permanent Link: HTML support in Matlab uicomponents'>HTML support in Matlab uicomponents</a> <small>Matlab uicomponents support HTML and CSS, enabling colored items, superscript/subscript, fonts, bold/italic/underline and many other modifications...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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>
<li><a href='http://undocumentedmatlab.com/blog/setprompt-setting-matlab-desktop-prompt/' rel='bookmark' title='Permanent Link: setPrompt &#8211; Setting the Matlab Desktop prompt'>setPrompt &#8211; Setting the Matlab Desktop prompt</a> <small>The Matlab Desktop's Command-Window prompt can easily be modified using some undocumented features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/' rel='bookmark' title='Permanent Link: Matlab layout managers: uicontainer and relatives'>Matlab layout managers: uicontainer and relatives</a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li>
</ol></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/matlab-dde-support/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Syntax highlighted labels &amp; panels</title>
		<link>http://undocumentedmatlab.com/blog/syntax-highlighted-labels-panels/</link>
		<comments>http://undocumentedmatlab.com/blog/syntax-highlighted-labels-panels/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 16:02:26 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1738</guid>
		<description><![CDATA[Syntax-highlighted labels and edit-boxes can easily be displayed in Matlab GUI - this article explains how. 

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Permanent Link: Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Permanent Link: Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='Permanent Link: 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><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, a reader of my article about <a target="_blank" href="http://undocumentedmatlab.com/blog/rich-matlab-editbox-contents/#comment-10760">rich Matlab editbox contents</a> asked whether it is possible to display syntax-highlighted contents, i.e. contents whose color changes based on its underlying text, often called <i>syntax hilite</i> in affection. I gave a very specific answer in a reply comment, which I expand in today&#8217;s full-length article.<br />
<!-- syntax highliting  syntax hiliting  syntax highlite  syntax hilite --></p>
<p>Matlab has two built-in Java classes that can present syntax-highlighted text: <b>SyntaxTextLabel</b> presents single-line labels, while <b>SyntaxTextPane</b> presents a multi-line editor pane. Both of these classes support C, HTML/XML, Java and Matlab syntax highlighting, as well as standard plaint-text. Some related <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/JIDE/">JIDE</a> classes are also described.</p>
<h3 id="SyntaxTextLabel">SyntaxTextLabel</h3>
<p>SyntaxTextLabel is used to display a syntax-highlighted single-line text label according to the specified programming language: C_STYLE, HTML_STYLE, JAVA_STYLE, PLAIN_STYLE and of course M_STYLE for Matlab code:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">str = <span style="color:#A020F0;">'for id=1:3, set(h(id),'</span><span style="color:#A020F0;">'string'</span><span style="color:#A020F0;">',num2str(id)); end  % Matlab code'</span>;
codeType = com.<span style="">mathworks</span>.<span style="">widgets</span>.<span style="">SyntaxTextLabel</span>.<span style="">M_STYLE</span>;
jCodeLabel = com.<span style="">mathworks</span>.<span style="">widgets</span>.<span style="">SyntaxTextLabel</span><span style="color: #080;">&#40;</span>str,codeType<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#91;</span>jhLabel,hContainer<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jCodeLabel,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 330px"><img alt="SyntaxTextLabels (different code styles)" src="http://UndocumentedMatlab.com/images/SyntaxTextLabel.png" title="SyntaxTextLabels (different code styles)" width="320" height="95" /><p class="wp-caption-text">SyntaxTextLabels (different code styles)</p></div></center></p>
<h3 id="StyledLabel">StyledLabel</h3>
<p>More flexibility in the displayed label styles can be achieved with <a target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">HTML/CSS</a>, and the bundled JIDE class <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/StyledLabel.html">com.jidesoft.swing.StyledLabel</a> provides even more flexibility:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">import java.<span style="">awt</span>.*
import com.<span style="">jidesoft</span>.<span style="">swing</span>.*
str = <span style="color:#A020F0;">'Mixed Underlined Strikethrough Super and Subscript combo Styles'</span>;
com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJUtilities</span>.<span style="">initJIDE</span>;
jStyledLabel = StyledLabel<span style="color: #080;">&#40;</span>str<span style="color: #080;">&#41;</span>; 
styles = <span style="color: #080;">&#91;</span>StyleRange<span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">5</span>,  Font.<span style="">BOLD</span>,   Color.<span style="">BLUE</span><span style="color: #080;">&#41;</span>, <span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">6</span>,<span style="color: #33f;">10</span>, Font.<span style="">PLAIN</span>,StyleRange.<span style="">STYLE_UNDERLINED</span><span style="color: #080;">&#41;</span>,<span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">17</span>,<span style="color: #33f;">13</span>,Font.<span style="">PLAIN</span>,  Color.<span style="">RED</span>,   <span style="color: #F0F;">...</span>
                           <span style="">StyleRange</span>.<span style="">STYLE_STRIKE_THROUGH</span><span style="color: #080;">&#41;</span>, <span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">31</span>,<span style="color: #33f;">5</span>, Font.<span style="">PLAIN</span>,  Color.<span style="">BLUE</span>,  <span style="color: #F0F;">...</span>
                           <span style="">StyleRange</span>.<span style="">STYLE_SUPERSCRIPT</span><span style="color: #080;">&#41;</span>, <span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">37</span>,<span style="color: #33f;">3</span>, Font.<span style="">ITALIC</span>, Color.<span style="">BLACK</span><span style="color: #080;">&#41;</span>, <span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">41</span>,<span style="color: #33f;">9</span>, Font.<span style="">PLAIN</span>,  Color.<span style="">BLUE</span>,  <span style="color: #F0F;">...</span>
                           <span style="">StyleRange</span>.<span style="">STYLE_SUBSCRIPT</span><span style="color: #080;">&#41;</span>, <span style="color: #F0F;">...</span>
          <span style="">StyleRange</span><span style="color: #080;">&#40;</span><span style="color: #33f;">51</span>,<span style="color: #33f;">5</span>, Font.<span style="">PLAIN</span>,  StyleRange.<span style="">STYLE_WAVED</span> + <span style="color: #F0F;">...</span>
                           <span style="">StyleRange</span>.<span style="">STYLE_STRIKE_THROUGH</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>;
jStyledLabel.<span style="">setStyleRanges</span><span style="color: #080;">&#40;</span>styles<span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>jhLabel,hContainer<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jStyledLabel,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 310px"><img alt="JIDE StyledLabel (different font styles)" src="http://UndocumentedMatlab.com/images/StyledLabel.png" title="JIDE StyledLabel (different font styles)" width="300" height="20" /><p class="wp-caption-text">JIDE StyledLabel (different font styles)</p></div></center></p>
<p>StyledLabels have subclasses that can be used to present styled text in tables, trees or lists. JIDE also provides the convenient <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/StyledLabelBuilder.html">StyledLabelBuilder</a>,  which enables easy multi-style text construction. </p>
<p>Finally, JIDE provides the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/ClickThroughStyledLabel.html">ClickThroughStyledLabel</a>, a StyledLabel extension that allows setting a target component, so that mouse clicks on the label will actually trigger the target component. This can be useful in forms where components have adjacent descriptive labels.</p>
<h3 id="SyntaxTextPane">SyntaxTextPane</h3>
<p>Multi-line syntax-highlighted code can be displayed with Matlab&#8217;s SyntaxTextPane class. SyntaxTextPane uses <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/MIME">MIME</a> types rather than styles for syntax-highlighting, but the end-result appears similar:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jCodePane = com.<span style="">mathworks</span>.<span style="">widgets</span>.<span style="">SyntaxTextPane</span>;
codeType = jCodePane.<span style="">M_MIME_TYPE</span>;  <span style="color: #228B22;">% ='text/m-MATLAB'</span>
jCodePane.<span style="">setContentType</span><span style="color: #080;">&#40;</span>codeType<span style="color: #080;">&#41;</span>
str = <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'% create a file for output\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'!touch testFile.txt\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'fid = fopen('</span><span style="color:#A020F0;">'testFile.txt'</span><span style="color:#A020F0;">', '</span><span style="color:#A020F0;">'w'</span><span style="color:#A020F0;">');\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'for i=1:10\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'    % Unterminated string:\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'    fprintf(fid,'</span><span style="color:#A020F0;">'%6.2f \\n, i);\n'</span> <span style="color: #F0F;">...</span>
       <span style="color:#A020F0;">'end'</span><span style="color: #080;">&#93;</span>;
str = <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>str,<span style="color:#A020F0;">'%'</span>,<span style="color:#A020F0;">'%%'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
jCodePane.<span style="">setText</span><span style="color: #080;">&#40;</span>str<span style="color: #080;">&#41;</span>
jScrollPane = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJScrollPane</span><span style="color: #080;">&#40;</span>jCodePane<span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>jhPanel,hContainer<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jScrollPane,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">100</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 340px"><img alt="SyntaxTextPane panel (Matlab MIME type)" src="http://UndocumentedMatlab.com/images/SyntaxTextPane.png" title="SyntaxTextPane panel (Matlab MIME type)" width="330" height="202" /><p class="wp-caption-text">SyntaxTextPane panel (Matlab MIME type)</p></div></center></p>
<p>The nice thing about SyntaxTextPane is that it syntax-highlights on-the-fly as you type or edit in the SyntaxTextPane (assuming you have not disabled editing with the <em>setEditable</em>(flag) method). This is exactly the behavior we have come to expect in the full-blown Matlab editor, and can now be embedded as a simple panel within our GUI.</p>
<p>Despite its misleadingly-simple look, SyntaxTextPane actually has most capabilities of the full-blown editor, not just syntax highlighting. This includes multiple undo/redo actions; smart indentation/commenting; automatic indication of corresponding block elements (if-end, for-end, etc. – also known as delimiter matching); search/replace, drag-and-drop and cut-copy-paste support; and many more.</p>
<p>Interested readers can use the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methodspropertiescallbacks-of-an-object"><i><b>uiinspect</b></i></a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/26947-checkclass"><i><b>checkClass</b></i></a> utilities to explore the full capabilities offered by SyntaxTextPane. In this respect it would be helpful to also look at its super-class (SyntaxTextPaneBase) and the related SyntaxTextPaneUtilities class.</p>
<h3 id="Summary">Summary</h3>
<p>These Java classes are examples of built-in classes that can be used in Matlab applications, enabling a much richer GUI experience than possible using the standard (documented/supported) Matlab widgets.</p>
<p>As I have shown above, using these classes is extremely easy, and requires absolutely no Java knowledge. On the flip side, these internal Matlab classes may easily break in any future Matlab release, so be extra careful when deciding to use them. Future articles in this website will describe other similarly-useful built-in classes.</p>
<p>Have you found any other useful built-in Matlab class? If so, please <a href="#respond">post a comment</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Permanent Link: Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Permanent Link: Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='Permanent Link: 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></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/syntax-highlighted-labels-panels/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Modifying Matlab&#8217;s Look-and-Feel</title>
		<link>http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/</link>
		<comments>http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 16:42:00 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JIDE]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1721</guid>
		<description><![CDATA[Matlab's entire Look-and-Feel (PLAF, or L&#038;F) can be modified at the control or application level - this article shows how

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/rich-matlab-editbox-contents/' rel='bookmark' title='Permanent Link: Rich Matlab editbox contents'>Rich Matlab editbox contents</a> <small>The Matlab editbox uicontrol does not handle HTML contents as do other uicontrols. In this article I show how this limitation can be removed....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Permanent Link: Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago, a reader of this blog <a target="_blank" href="http://undocumentedmatlab.com/blog/changing-matlab-command-window-colors/#comment-12043">posted a comment</a>, asking whether it is possible to change Matlab&#8217;s Desktop color scheme, and its general UI look. Instead of providing a short answer, I will use the opportunity to answer in a full article. So this is for you, Egon <img src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3 id="PLAF">Matlab&#8217;s underlying Look-and-Feel</h3>
<p>One of Matlab&#8217;s great advantages is cross-platform compatibility. Generally speaking, Matlab applications written on Windows will work as-is on Macintosh and Linux.</p>
<p>Java has similar cross-platform compatibilities, but enables much greater control over the <em>look-and-feel</em> (L&#038;F or <em><a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html">PLAF</a></em>) of application GUI. In a nutshell, L&#038;Fs affect the appearance and behavior of menus, controls, color schemes etc., using a <a target="_blank" rel="nofollow" href="http://java.sun.com/products/jfc/tsc/articles/architecture/#pluggable">properties plug-in architecture</a>. Java programmers can choose to use either a platform-independent L&#038;F (called the <em>Metal L&#038;F</em>), or a platform-specific L&#038;F. The benefit of using Metal is that the application looks essentially the same on all Java-supported platforms; the drawback is that they do not look like native applications on any platform&#8230;</p>
<p><center><div class="wp-caption aligncenter" style="width: 380px"><img alt="Metal L&#038;F" src="http://UndocumentedMatlab.com/images/plaf_metal2.png" title="Metal L&#038;F" width="122" height="42" /> &nbsp; <img alt="Motif L&#038;F" src="http://UndocumentedMatlab.com/images/plaf_motif2.png" title="Motif L&#038;F" width="100" height="48" /> &nbsp; <img alt="Windows L&#038;F" src="http://UndocumentedMatlab.com/images/plaf_windows2.png" title="Windows L&#038;F" width="101" height="44" /><p class="wp-caption-text">Metal, Motif &#038; Windows L&#038;F</p></div></center></p>
<p>Matlab, whose GUI is based on Java (not surprising to readers of this website), has chosen to use a platform-specific L&#038;F on each of the platforms on which it is supported. So, Matlab on Windows looks like a native Windows application, whereas on Macs it looks similar to Mac apps (notwithstanding the well-known <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2009/08/31/pouncing-on-snow-leopard/">X11 migration issues</a>). Of course, this means that Windows Matlab looks and behaves differently from Mac/Linux Matlabs. Note that the differences only affect the Desktop, tools/utilities (Editor etc.) and the general L&#038;F &#8211; it does not affect the displayed plots. In practice, the differences are visible but easily understandable.</p>
<h3 id="Change_PLAF">Changing the L&#038;F</h3>
<p>We can get the list of available L&#038;Fs on our system as follows (below is the list on my Windows system):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; lafs = javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">getInstalledLookAndFeels</span>
lafs =
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #F0F;">:</span>
    <span style="color: #080;">&#91;</span>javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">for</span> lafIdx = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>lafs<span style="color: #080;">&#41;</span>,  <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>lafs<span style="color: #080;">&#40;</span>lafIdx<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #0000FF;">end</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span>Metal javax.<span style="">swing</span>.<span style="">plaf</span>.<span style="">metal</span>.<span style="">MetalLookAndFeel</span><span style="color: #080;">&#93;</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span>Nimbus com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">nimbus</span>.<span style="">NimbusLookAndFeel</span><span style="color: #080;">&#93;</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span>CDE/Motif com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">motif</span>.<span style="">MotifLookAndFeel</span><span style="color: #080;">&#93;</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span>Windows com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">windows</span>.<span style="">WindowsLookAndFeel</span><span style="color: #080;">&#93;</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>$LookAndFeelInfo<span style="color: #080;">&#91;</span>Windows Classic com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">windows</span>.<span style="">WindowsClassicLookAndFeel</span><span style="color: #080;">&#93;</span></pre></div></div>

<p>We can change the L&#038;F to any of the installed L&#038;Fs, as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">setLookAndFeel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.plaf.metal.MetalLookAndFeel'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Although not listed in the installed L&#038;Fs, Matlab also enables access to a 3rd-party L&#038;F called <a target="_blank" rel="nofollow" href="http://www.jgoodies.com/freeware/looks/index.html">Plastic3D</a> by <a target="_blank" rel="nofollow" href="http://www.jgoodies.com">www.jgoodies.com</a>. Plastic3D L&#038;F generates slick stylish GUI:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">setLookAndFeel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'com.jgoodies.looks.plastic.Plastic3DLookAndFeel'</span><span style="color: #080;">&#41;</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 116px"><img alt="Plastic3D L&#038;F" src="http://UndocumentedMatlab.com/images/plaf_plastic2.png" title="Plastic3D L&#038;F" width="106" height="44" /><p class="wp-caption-text">Plastic3D L&#038;F</p></div></center></p>
<p>The <a target="_blank" href="http://UndocumentedMatlab.com/blog/tag/jide/">JIDE class library</a> by <a target="_blank" rel="nofollow" href="www.jidesoft.com">www.jidesoft.com</a>, which is bundled with Matlab, and specifically its jide-common.jar file, contains a separate set of 3rd-party L&#038;Fs: Aqua, Eclipse (Metal &#038; Windows variants), Office2003, VSNet (Metal &#038; Windows variants) and Xerto. Unfortunately, in Matlab releases starting around 2009, JIDE stopped including full L&#038;F classes in jide-common.jar, and started using L&#038;F extensions using their <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/plaf/LookAndFeelFactory.html">com.jidesoft.plaf.LookAndFeelFactory</a> class. I have not been able to use this class properly, but readers are welcome to try (please tell me if you succeed).</p>
<p>External L&#038;Fs can also be downloaded and then used in Matlab. For example: <a target="_blank" rel="nofollow" href="http://lookandfeel.incors.com/">Alloy</a>, <a target="_blank" rel="nofollow" href="http://www.javasoft.de/synthetica/">Synthetica</a> and many others.</p>
<p>The current and standard L&#038;Fs can be retrieved by using the respective static methods javax.swing.UIManager.<em>getLookAndFeel()</em> and <em>getSystemLookAndFeelClassName()</em>.</p>
<p>Matlab also has a utility class com.mathworks.mwswing.plaf.PlafUtils that contains static methods that query the current L&#038;F: <em>isPlasticLookAndFeel(), isAquaLookAndFeel(),  isMetalLookAndFeel(), isMotifLookAndFeel()</em> and <em>isWindowsLookAndFeel()</em>. For some reason there is no method for the new (R2010a+) <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/nimbus.html">Nimbus L&#038;F</a>.</p>
<p>Nimbus L&#038;F offers great potential for a cross-platform vectorized appearance, the ability to customize/skin pretty much every aspect of the visual appearance and component behavior, replacing Swing&#8217;s <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/synth.html">Synth L&#038;F</a> which was used for such customizations in earlier Matlab/Java releases. Nimbus is pre-installed as a non-default L&#038;F in Matlab R2010a (7.10) onward, because it seems that most designers who target a single platform still <a target="_blank" rel="nofollow" href="http://www.jasperpotts.com/blog/2009/03/breakdown-of-what-should-be-default-laf-for-java-7/">prefer the native L&#038;F</a>.</p>
<h3 id="Component_PLAF">Component-specific L&#038;F</h3>
<p>You can also modify the L&#038;F of specific components, not just the entire Matlab. To do this, simply modify the L&#038;F immediately before creating your GUI component, and restore the original L&#038;F afterward (note how you can use either the L&#038;F class name or its class reference):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Update the current L&amp;F</span>
originalLnF = javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">getLookAndFeel</span>;  <span style="color: #228B22;">%class</span>
newLnF = <span style="color:#A020F0;">'javax.swing.plaf.metal.MetalLookAndFeel'</span>;  <span style="color: #228B22;">%string</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">setLookAndFeel</span><span style="color: #080;">&#40;</span>newLnF<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Create GUI using the modified L&amp;F</span>
hFig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
hComponent = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
jComponent = javacomponent<span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Restore the original L&amp;F</span>
javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">setLookAndFeel</span><span style="color: #080;">&#40;</span>originalLnF<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Components can update their L&#038;F to the current L&#038;F using their jComponent.<em>updateUI()</em> method. Components that are not specifically updated by invoking their <em>updateUI()</em> method will retain their existing (original) L&#038;F – the L&#038;F which was active when the components were created or last updated.</p>
<h3 id="Properties">Fine-grained L&#038;F property control</h3>
<p>The default settings for the L&#038;F can be retrieved using the static method javax.swing.UIManager.<em>getDefaults()</em>, which returns an enumeration of the thousand or so default settings:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; defaults = javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">getDefaults</span>;
&gt;&gt; propValues = defaults.<span style="">elements</span>; propKeys = defaults.<span style="">keys</span>;
&gt;&gt; <span style="color: #0000FF;">while</span> propKeys.<span style="">hasMoreElements</span>
     key = propKeys.<span style="">nextElement</span>;
     value = propValues.<span style="">nextElement</span>;
     <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #0000FF;">char</span><span style="color: #080;">&#40;</span>key<span style="color: #080;">&#41;</span> <span style="color:#A020F0;">' = '</span> <span style="color: #0000FF;">evalc</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'disp(value)'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">end</span>
&nbsp;
com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">windows</span>.<span style="">WindowsLabelUI</span> = <span style="color: #0000FF;">class</span> com.<span style="">sun</span>.<span style="">java</span>.<span style="">swing</span>.<span style="">plaf</span>.<span style="">windows</span>.<span style="">WindowsLabelUI</span>
<span style="color: #F0F;">...</span> <span style="color: #080;">&#40;</span>~<span style="color: #33f;">1000</span> other property settings<span style="color: #080;">&#41;</span>
SplitPane.<span style="">dividerSize</span> =      <span style="color: #33f;">5</span>
DockableFrameTitlePane.<span style="">stopAutohideIcon</span> = javax.<span style="">swing</span>.<span style="">ImageIcon</span>@1f4e4c0
FormattedTextField.<span style="">caretBlinkRate</span> =    <span style="color: #33f;">500</span>
Table.<span style="">gridColor</span> = javax.<span style="">swing</span>.<span style="">plaf</span>.<span style="">ColorUIResource</span><span style="color: #080;">&#91;</span>r=<span style="color: #33f;">128</span>,g=<span style="color: #33f;">128</span>,b=<span style="color: #33f;">128</span><span style="color: #080;">&#93;</span></pre></div></div>

<p>Specific settings can be modified by using javax.swing.UIManager.<em>put(key,newValue)</em>.</p>
<p>Have you found any useful L&#038;F or property that you are using in your application? If so, please share them in the <a href="#respond">comments</a> section below.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/rich-matlab-editbox-contents/' rel='bookmark' title='Permanent Link: Rich Matlab editbox contents'>Rich Matlab editbox contents</a> <small>The Matlab editbox uicontrol does not handle HTML contents as do other uicontrols. In this article I show how this limitation can be removed....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Permanent Link: Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Permanent Link: 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></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Date selection components</title>
		<link>http://undocumentedmatlab.com/blog/date-selection-components/</link>
		<comments>http://undocumentedmatlab.com/blog/date-selection-components/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 06:43:53 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1684</guid>
		<description><![CDATA[The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used

 
<pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Permanent Link: Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/advanced-jide-property-grids/' rel='bookmark' title='Permanent Link: Advanced JIDE Property Grids'>Advanced JIDE Property Grids</a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='Permanent Link: 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><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered why Matlab does not have standard GUI date-handling components?</p>
<p>Matlab has many built-in date-handling functions (<i><b>calendar, date, datestr, datenum, datetick, datevec</b></i> etc.). Unfortunately, this built-in support does not extend to Matlab GUI. If we need a date-selection drop-down or calendar panel we have to design it ourselves, or use a third-party Java component or ActiveX control. </p>
<h3 id="JIDE">JIDE Components</h3>
<p>Luckily, we have a much better alternative, right within Matlab. This relies on the undocumented fact that Matlab uses <a target="_blank" rel="nofollow" href="http://www.jidesoft.com">JIDE components</a> for many of its GUI components. As already explained <a target="_blank" href="http://undocumentedmatlab.com/blog/jide-property-grids/">earlier</a>, JIDE controls are pre-bundled in Matlab (/java/jarext/jide/jide-grids.jar under the Matlab root). 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> (pages 28-35) and the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/">Javadoc documentation</a>. </p>
<p>In particular, JIDE Grids includes the following date-selection controls:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateChooserPanel.html">DateChooserPanel</a> &#8211; an extension of Swing&#8217;s JPanel that displays a single month and enables selecting one or more days</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/CalendarViewer.html">CalendarViewer</a>  &#8211; a similar panel, that displays several months in a table-format (e.g., 4&#215;3 months)</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateComboBox.html">DateComboBox</a> &#8211; a combo-box (drop-down/popup menu) that presents a DateChooserPanel for selecting a date</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/DateSpinnerComboBox.html">DateSpinnerComboBox</a> &#8211; presents a date-selection combo-box that includes both the DateComboBox and a spinner control (this control is only available in the latest Matlab releases)</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MonthChooserPanel.html">MonthChooserPanel</a> &#8211; a panel that enables selection of entire months (not specific dates)</li>
<li><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/combobox/MonthComboBox.html">MonthComboBox</a> &#8211; a month selection combo-box, similar to DateComboBox but without the ability to select individual days</li>
</ul>
<p>Usage of these controls is very similar, so I&#8217;ll just show the basics here. First, to present any control, we need to use the built-in <i><b>javacomponent</b></i> function or the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14583-uicomponent-expands-uicontrol-to-all-java-classes">uicomponent</a></b></i> utility:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Initialize JIDE's usage within Matlab</span>
com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJUtilities</span>.<span style="">initJIDE</span>;
&nbsp;
<span style="color: #228B22;">% Display a DateChooserPanel</span>
jPanel = com.<span style="">jidesoft</span>.<span style="">combobox</span>.<span style="">DateChooserPanel</span>;
<span style="color: #080;">&#91;</span>hPanel,hContainer<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jPanel,<span style="color: #080;">&#91;</span><span style="color: #33f;">10</span>,<span style="color: #33f;">10</span>,<span style="color: #33f;">200</span>,<span style="color: #33f;">200</span><span style="color: #080;">&#93;</span>,<span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span></pre></div></div>

<p><center><br />
<div class="wp-caption aligncenter" style="width: 420px"><img alt="DateChooserPanel" src="http://UndocumentedMatlab.com/images/JIDE_DateChooserPanel.png" title="DateChooserPanel" width="200" height="200" /> &nbsp; <img alt="MonthChooserPanel" src="http://UndocumentedMatlab.com/images/JIDE_MonthChooserPanel.png" title="MonthChooserPanel" width="200" height="200" /><p class="wp-caption-text">DateChooserPanel and MonthChooserPanel components</p></div></p>
<p><div class="wp-caption aligncenter" style="width: 410px"><img alt="CalendarViewer" src="http://UndocumentedMatlab.com/images/JIDE_CalendarViewer.png" title="CalendarViewer" width="400" height="300" /><p class="wp-caption-text">2x2 CalendarViewer component</p></div><br />
</center></p>
<p>Just as with any Java object, properties may either be accessed with the Java accessor methods (e.g. <em>getName()</em> or <em>setName(name)</em>), or the Matlab get/set semantics (e.g. <i><b>get</b></i>(prop,&#8217;Name&#8217;)  or <i><b>set</b></i>(prop,&#8217;Name&#8217;,value)). When using the Matlab syntax, remember to wrap the Java object in a <i><b>handle</b></i>() call, to prevent a memory leak (or use hPanel rather than jPanel):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jPanel.<span style="">setShowWeekNumbers</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;    <span style="color: #228B22;">% Java syntax</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hPanel,<span style="color:#A020F0;">'ShowTodayButton'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% Matlab syntax</span></pre></div></div>

<p>Retrieving the selected date is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; selectedDate = jPanel.<span style="">getSelectedDate</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
selectedDate =
Sun Jun <span style="color: #33f;">27</span> 00<span style="color: #F0F;">:</span>00<span style="color: #F0F;">:</span>00 IDT <span style="color: #33f;">2010</span>
<span style="color: #228B22;">% or: selectedDate = get(jPanel,'SelectedDate');</span>
&nbsp;
<span style="color: #228B22;">% Note: selectedDate is a java.util.Date object:</span>
&gt;&gt; selectedDate.<span style="color: #0000FF;">get</span>
	<span style="color: #0000FF;">Class</span> = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">1</span> by <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> java.<span style="">lang</span>.<span style="color: #0000FF;">Class</span> array<span style="color: #080;">&#93;</span>
	<span style="color: #0000FF;">Date</span> = <span style="color: #080;">&#91;</span><span style="color: #33f;">27</span><span style="color: #080;">&#93;</span>
	Day = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
	Hours = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
	Minutes = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
	Month = <span style="color: #080;">&#91;</span><span style="color: #33f;">5</span><span style="color: #080;">&#93;</span>
	Seconds = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
	Time = <span style="color: #080;">&#91;</span>1.27759e+012<span style="color: #080;">&#93;</span>
	TimezoneOffset = <span style="color: #080;">&#91;</span>-<span style="color: #33f;">180</span><span style="color: #080;">&#93;</span>
	Year = <span style="color: #080;">&#91;</span><span style="color: #33f;">110</span><span style="color: #080;">&#93;</span></pre></div></div>

<p>We can enable selection of multiple dates (SINGLE_SELECTION=0, SINGLE_INTERVAL_SELECTION=1,MULTIPLE_INTERVAL_SELECTION=2):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jModel = hPanel.<span style="">getSelectionModel</span>;  <span style="color: #228B22;">% a com.jidesoft.combobox.DefaultDateSelectionModel object</span>
jModel.<span style="">setSelectionMode</span><span style="color: #080;">&#40;</span>jModel.<span style="">MULTIPLE_INTERVAL_SELECTION</span><span style="color: #080;">&#41;</span>;
&nbsp;
&gt;&gt; hPanel.<span style="">getSelectionModel</span>.<span style="">getSelectedDates</span>
<span style="color: #0000FF;">ans</span> =
java.<span style="">util</span>.<span style="color: #0000FF;">Date</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #F0F;">:</span>
    <span style="color: #080;">&#91;</span>java.<span style="">util</span>.<span style="color: #0000FF;">Date</span><span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>java.<span style="">util</span>.<span style="color: #0000FF;">Date</span><span style="color: #080;">&#93;</span>
    <span style="color: #080;">&#91;</span>java.<span style="">util</span>.<span style="color: #0000FF;">Date</span><span style="color: #080;">&#93;</span></pre></div></div>

<p>And of course we can set a callback for whenever the user modifies the selected date(s):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hModel = handle<span style="color: #080;">&#40;</span>hPanel.<span style="">getSelectionModel</span>, <span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hPanel, <span style="color:#A020F0;">'ValueChangedCallback'</span>, @myCallbackFunction<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>For the combo-box (drop-down/popup menus) controls, we obviously need to modify the displayed size (in the <i><b>javacomponent</b></i> call) to something much more compact, such as [10,10,100,20]. These components display one of the above panels as their pop-up selection panels. Users can access and customize these panels using the combo-box control&#8217;s <em>getPopupPanel()</em> function (or <strong>PopupPanel</strong> property).<br />
<center><div class="wp-caption aligncenter" style="width: 420px"><img alt="DateComboBox" src="http://UndocumentedMatlab.com/images/JIDE_DateComboBox.png" title="DateComboBox" width="200" height="166" /> &nbsp; <img alt="DateSpinnerComboBox" src="http://UndocumentedMatlab.com/images/JIDE_DateSpinnerComboBox.png" title="DateSpinnerComboBox" width="200" height="166" /><p class="wp-caption-text">DateComboBox and DateSpinnerComboBox components</p></div></center></p>
<p>Numerous other customizations are possible with these JIDE components &#8211; have fun exploring (my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methodspropertiescallbacks-of-an-object"><i><b>uiinspect</b></i> utility</a> can be quite handy in this)! Just remember that JIDE evolves with Matlab, and so JIDE&#8217;s online documentation, which refers to the latest JIDE version, may be partially inapplicable if you use an old Matlab version. The older your Matlab, the more such inconsistencies that you may find.</p>
<h3 id="Alternatives">Alternative components</h3>
<p>There are several alternatives to the JIDE components:</p>
<p>If we have Matlab&#8217;s Financial toolbox, we can use the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/toolbox/finance/uicalendar.html">uicalendar</a></b></i> function. Unfortunately, this control is not available if you don&#8217;t own the expensive Financial toolbox.</p>
<p>If we only target Windows-based platforms, we could use third-party ActiveXes such as the Microsoft Date-and-Time-Picker (MSComCtl2.DTPicker.2), Microsoft MonthView (MSComCtl2.MonthView.2) or the Microsoft Office Calendar (MSCAL.Calendar.7) ActiveX controls. Depending on your installed applications, you may have other similar controls. For example, if you have Symantec&#8217;s EndPoint Protection (SEP), you have access to the SEP Date Control (LDDATETIME.LDDateCtrl.1). Of course, these controls will not work on non-Windows platforms, or platforms that do not have these ActiveX controls installed.</p>
<p>We can also use other (non-JIDE) third-party Java controls from places like javashareware.com, swinglabs.org, downloadthat.com, sharewareconnection.com, easyfreeware.com, l2fprod.com,  fileheap.com/software/components.html, swing-components.safe-install.com and many others. One specific example is <a target="_blank" rel="nofollow" href="http://nachocalendar.sourceforge.net/">NachoCalendar</a>, from SourceForge.com.</p>
<p>Finally, we could use some of the utilities posted on the Matlab File Exchange: <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15913-yet-another-calendar">uical</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/5915-uisetdate">uisetdate</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/26560-calender">calender</a> (sic) and several others.</p>
<p>In my own biased opinion, none of these alternatives comes close to the ease-of-use and functionality of the JIDE components presented above. What do you think? Please add your comments <a target="_blank" rel="nofollow" href="#respond">here</a>.</p>


 <p><pre> </pre>Related posts:<ol><li><a href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Permanent Link: Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Permanent Link: 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='http://undocumentedmatlab.com/blog/advanced-jide-property-grids/' rel='bookmark' title='Permanent Link: Advanced JIDE Property Grids'>Advanced JIDE Property Grids</a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='Permanent Link: 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></p><pre> </pre>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/date-selection-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
