<?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>AppDesigner &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/appdesigner/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 01 Aug 2018 18:00:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Customizing web-GUI uipanel</title>
		<link>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-web-gui-uipanel</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 01 Aug 2018 18:00:13 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Iliya Romm]]></category>
		<category><![CDATA[Khris Griffis]]></category>
		<category><![CDATA[uifigure]]></category>
		<category><![CDATA[uipanel]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7804</guid>

					<description><![CDATA[<p>We can customize Matlab's new web-based GUI  panels in many interesting ways. Here's how... </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel">Customizing web-GUI uipanel</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-uipanels" rel="bookmark" title="Customizing Matlab uipanels">Customizing Matlab uipanels </a> <small>Matlab uipanel controls can be customized using Java in ways that are impossible with plain Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-3-backdrop" rel="bookmark" title="Customizing axes part 3 &#8211; Backdrop">Customizing axes part 3 &#8211; Backdrop </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger <a href="https://github.com/Khlick" rel="nofollow" target="_blank">Khris Griffis</a>. Today, Khris will continue the series of posts on <a href="https://undocumentedmatlab.com/articles/tag/uifigure" target="_blank">web-based uifigure customization</a> with an article showing how to create scrollable/customizable panels in web-based uifigures. This post follows <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">last-week&#8217;s article</a>, about placing controls/axes within a scroll-panel in non-web (Java-based) figures. Users interested in advanced aspects and insights on the development roadmap of web-based Matlab GUI should also read <a href="https://blogs.mathworks.com/loren/2018/07/25/the-state-of-app-building-in-matlab" rel="nofollow" target="_blank">Loren Shure&#8217;s blog post from last week</a>.</i></p>
<h3 id="Motivation">Motivation</h3>
<p>As a retinal physiologist, I spend a lot of time in Matlab creating GUIs to visualize and analyze electrophysiological data. The data often requires a lot of processing and quality control checks before it can be used for interpretation and publication. Consequently, I end up with many control elements taking up precious space on my GUI.<br />
In Java-based (legacy/GUIDE) figures, this wasn&#8217;t a huge problem because, depending on what GUI components I needed, I could use a pure Matlab approach (a child panel within a parent panel, with a couple of control sliders moving the child panel around), or a number of Java approaches (which are always more fun; Yair <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">described such an approach</a> last week).<br />
Unfortunately, the web-based (App-Designer) figure framework doesn&#8217;t support Java, and the pure/documented Matlab approach just doesn&#8217;t look good or function very well:<br />
<!--
If you're like me, you've once (or twice) queried your favorite search engine with "<i>Matlab scrolling uipanel</i>" and found 2 useful methods: a pure Matlab approach and <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">a fun Java approach</a> (sticking objects in a <code>JScrollPane</code>, as explained in last week's post). Now, we read <i>Undocumented Matlab</i>, so we typically opt for the Java approach and our app is beautiful and the world is right... and countless hours of my life will go completely unnoticed by everyone using my app. But then the internet gets fast enough, servers get big enough, or for whatever reason, browser-/web-based apps are now <i>the</i> thing, so The Mathworks Inc. went and developed the <i><b>uifigure</b></i> to, you know, catch up.
The problem is, the new web framework eliminates our ability to use the Java approach and severely dampens the aesthetic of a pure Matlab approach (a child panel within a parent panel, with a couple of control sliders moving the child panel around). And that approach was already pretty ugly, if you care about that kind of stuff. So how can we make a scrolling <i><b>uipanel</b></i> to hold all these fancy, new <i><b><a href="https://www.mathworks.com/help/matlab/ref/uiknob.html" rel="nofollow" target="_blank">uiknob</a></b></i> controls?
--><br />
<center style="font-size:12px;"><img fetchpriority="high" decoding="async" src="https://undocumentedmatlab.com/images/uipanel_badscrolls.png" alt="AppDesigner uislider is not a good scrollbar, no matter what we do to it!" title="AppDesigner uislider is not a good scrollbar, no matter what we do to it!" width="473" height="187" /><br />
AppDesigner <i><b>uislider</b></i> is not a good scrollbar, no matter what we do to it!</center><br />
Fortunately, the new web framework allows us to use HTML, CSS and JavaScript (JS) to modify elements in the <i><b>uifigure</b></i>, i.e. its web-page <a href="https://en.wikipedia.org/wiki/Document_Object_Model" rel="nofollow" target="_blank">DOM</a>. It turns out that the <i><b>uipanel</b></i> object is essentially just a <code>&lt;div&gt;</code> with a Matlab-designed CSS style. We can customize it with little effort.<br />
The main goal here is to create a scrollable customizable <i><b>uipanel</b></i> containing many uicontrol elements, which could look something like this:<br />
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_ADfig_1.png" alt="Running app demo" title="Running app demo" width="450" height="355" style="max-width:804px;"/></center><br />
<span id="more-7804"></span></p>
<h3 id="Example">A simple command-window example</h3>
<p>Since we are building on the series of <i><b>uifigure</b></i> customizations, I expect you have already read the preceding related <i>Undocumented Matlab</i> posts:</p>
<ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" target="_blank">Customizing uifigures part 1</a></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" target="_blank">Customizing uifigures part 2</a></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" target="_blank">Customizing uifigures part 3</a></li>
</ol>
<p>Also, I <i>highly recommend</i> cloning (or at least downloading) the <a href="https://github.com/StackOverflowMATLABchat/mlapptools" rel="nofollow" target="_blank">mlapptools toolbox</a> repo on Github (thanks <a href="http://bcukurel.net.technion.ac.il" rel="nofollow" target="_blank">Iliya Romm</a> et al.). We will use it to simplify life today.<br />
<!--
Alright, let's say your GUI calls for a scroll-panel full of knobs, because who doesn't love having a plethora of knobs around?
<center><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_scrollApp.gif" alt="A scrollable panel can hide control widgets easily!" title="A scrollable panel can hide control widgets easily!" width="80%" style="max-width:822px;" /></center>
--><br />
Using the <code>mlapptools</code> toolbox, we need just a few lines of code to set up a scrollable panel. The important thing is knowing how big the panel needs to be to hold all of our control objects. Once we know this, we simply set the panel&#8217;s <b>Position</b> property accordingly. Then we can use simple CSS to display scrollbars and define the viewing dimensions.<br />
For example, if we need 260px in width by 720px in height to hold our control widgets, but only have 200px height available, we can solve this problem in 3 steps:</p>
<ol>
<li>Set the <i><b>uipanel</b></i>&#8216;s <b>Dimension</b> property to be 260px wide by 720px tall.</li>
<li>Set the viewing height using <code>mlapptools.setStyle(scrollPane,'height','200px')</code> for the panel&#8217;s CSS <code>height</code> style attribute.</li>
<li>Display the vertical scrollbar by calling <code>mlapptools.setStyle(scrollPane,'overflow-y','scroll')</code> for the panel&#8217;s CSS <code>overflow-y='scroll'</code> style attribute.</li>
</ol>
<pre lang="matlab">
% Create the figure
fig = uifigure('Name', 'Scroll Panel Test');
% Place a uipanel on the figure, color it for fun
scrollPane = uipanel(fig, 'BackgroundColor', [0.5,0.4,1]);
% Define the space requirements for the controls
totalWidth  = 260; %px
totalHeight = 720; %px
viewHeight  = 200; %px
% STEP 1: set the uipanel's Position property to the required dimensions
scrollPane.Position(3) = totalWidth;  % WIDTH
scrollPane.Position(4) = totalHeight; % HEIGHT
% STEP 2: set the viewing height
mlapptools.setStyle(scrollPane, 'height', sprintf('%dpx', viewHeight));
% STEP 3: display the vertical scrollbar
mlapptools.setStyle(scrollPane, 'overflow-y', 'scroll');
% Add control elements into the uipanel
...
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_exampleFig.png" alt="Example scrollable uipanel in a Matlab uifigure" title="Example scrollable uipanel in a Matlab uifigure" width="70%" style="max-width:450px;"/><!-- 619px --><br />
Example scrollable uipanel in a Matlab uifigure</center><br />
Because this is a web-based GUI, notice that you can simply hover your mouse over the panel and scroll with your scroll wheel. Awesome, right?<br />
Note that the CSS <code>height</code>/<code>width</code> style attributes don&#8217;t affect the actual size of our panel, just how much of the panel we can see at once (&#8220;viewport&#8221;).<br />
The CSS <code>overflow</code> style attribute has a number of options. For example, <code>setStyle(scrollPane,'overflow','auto')</code> causes scrollbars to automatically hide when the viewing area is larger than panel&#8217;s dimensions. Review the <a href="https://www.w3schools.com/css/css_overflow.asp" rel="nofollow" target="_blank">CSS <code>overflow</code> attribute</a> to learn about other related settings that affect the panel&#8217;s behavior.</p>
<h3 id="Scrollbars">Styling the scrollbars</h3>
<p>The <code>mlapptools</code> toolbox utilizes <i>dojo.js</i> to query the DOM and set styles, which is essentially setting inline styles on the DOM element, i.e. <code>&lt;div ... style="color: red;background:#FEFEFE;..."&gt; ... &lt;/div&gt;</code>. This has the added benefit of overriding any CSS classes Matlab is imposing on the DOM (see <a href="https://css-tricks.com/precedence-css-order-css-matters" rel="nofollow" target="_blank">CSS precedence</a>). We can inject our own classes into the page&#8217;s <code>&lt;head&gt;</code> tag and then use <code>dojo.setClass()</code> to apply our classes to specific GUI elements. For example, we can style our bland scrollbars by using CSS to define a custom <code>scrollpane</code> style class:</p>
<pre lang="css">
/* CSS To stylize the scrollbar */
.scrollpane::-webkit-scrollbar {
  width: 20px;
}
/* Track */
.scrollpane::-webkit-scrollbar-track {
  background-color: white;
  box-shadow: inset 0 0 5px white;
  border-radius: 10px;
}
/* Handle */
.scrollpane::-webkit-scrollbar-thumb {
  background: red;
  border-radius: 10px;
}
/* Handle on hover */
.scrollpane::-webkit-scrollbar-thumb:hover {
  background: #b30000;
}
</pre>
<p>To get the CSS into the document header, we need to first convert (&#8220;stringify&#8221;) it in Matlab:</p>
<pre lang="matlab">
% CSS styles 'stringified' for MATLAB
%  note that the whole style tag is wrapped in single quotes, that is required!
%  i.e. '<style>...</style>' which prints to the command window as:
%   ''<style>...</style>''
cssText = [...
  '''<style>\n', ...
  '  .scrollpane::-webkit-scrollbar {\n', ...
  '    width: 20px;\n', ...
  '  }\n', ...
  '  /* Track */\n', ...
  '  .scrollpane::-webkit-scrollbar-track {\n', ...
  '    background-color: white;\n', ...
  '    box-shadow: inset 0 0 5px white;\n', ...
  '    border-radius: 10px;\n', ...
  '  }\n', ...
  '  /* Handle */\n', ...
  '  .scrollpane::-webkit-scrollbar-thumb {\n', ...
  '    background: red; \n', ...
  '    border-radius: 10px;\n', ...
  '  }\n', ...
  '  /* Handle on hover */\n', ...
  '  .scrollpane::-webkit-scrollbar-thumb:hover {\n', ...
  '    background: #b30000; \n', ...
  '  }\n', ...
  '</style>''' ...
  ];
</pre>
<p>As explained in <a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" target="_blank">Customizing uifigures part 1</a>, we can execute JavaScript (JS) commands through the <code>webWindow</code> object. To simplify it, we use the method from <a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" target="_blank">Customizing uifigures part 2</a> to obtain the <code>webWindow</code> object for our GUI window and and use the <code>executeJS()</code> method to add our HTML into the document&#8217;s <code>&lt;head&gt;</code> tag. It is worth checking out the properties and methods of <a href="https://www.w3schools.com/jsref/dom_obj_document.asp" rel="nofollow" target="_blank">the JS <code>document</code> object</a>.</p>
<pre lang="matlab">
% get the webWindow object
webWindow = mlapptools.getWebWindow(fig);
% inject the CSS
webWindow.executeJS(['document.head.innerHTML += ',cssText]);
</pre>
<p>Now the tricky part is that we have to assign our new CSS <code>scrollpane</code> class to our <i><b>uipanel</b></i>. We need 2 things: the <code>webWindow</code> object and the <code>data-tag</code> (our panel&#8217;s unique ID) attribute.</p>
<pre lang="matlab">
% get the uipanel data-tag attr.
[webWindow, panelID] = mlapptools.getWebElements(scrollPane);
%make a dojo.js statement (use addClass method)
setClassString = sprintf(...
  'dojo.addClass(dojo.query("[%s = ''%s'']")[0], "%s")',...
  panelID.ID_attr, panelID.ID_val, 'scrollpane');
% add class to DOM element
webWindow.executeJS(setClassString);
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_styledScroll.gif" alt="The results of applying our scrollpane CSS style on our scroll-pane's scrollbars" title="The results of applying our scrollpane CSS style on our scroll-pane's scrollbars" width="70%" style="max-width:450px;"/><!-- 566px --><br />
The results of applying our <code>scrollpane</code> CSS style on our scroll-pane&#8217;s scrollbars</center><br />
Note: Unfortunately, because of CSS precedence rules, we may have to use the dreaded <a href="https://www.smashingmagazine.com/2010/11/the-important-css-declaration-how-and-when-to-use-it" rel="nofollow" target="_blank"><code>!important</code> CSS qualifier</a> to get the desired effect. So if the result doesn&#8217;t match your expectations, try adding <code>!important</code> to the CSS class attributes.</p>
<h3 id="uipanel">Styling the <i>uipanel</i></h3>
<p>Each <i><b>uipanel</b></i> appears to be composed of 4 <code>&lt;div&gt;</code> HTML elements: a wrapper, internal container for the panel title, a separator, and the panel&#8217;s body (contents). We first use <code>mlapptools.getWebElements()</code> to get the <code>data-tag</code> ID for the wrapper node. We can then apply styles to the wrapper, or any child node, with CSS and JS.<br />
For example, we can use CSS3 patterns (such as one in <a href="http://lea.verou.me/css3patterns/#" rel="nofollow" target="_blank">this CSS3 gallery</a>) to liven up our panel. We can also use CSS to define a block element that will replace the title container with some static text. The CSS below would be appended to the <code>cssText</code> string we made for styling the scrollbars above:</p>
<pre lang="css">
/* DECORATE THE BACKGROUND */
/* Stars modified from: http://lea.verou.me/css3patterns/#stars */
.scrollpane {
  overflow: auto;
  background:
  linear-gradient(324deg, #232927 4%,   transparent 4%)   -70px 43px,
  linear-gradient( 36deg, #232927 4%,   transparent 4%)    30px 43px,
  linear-gradient( 72deg, #e3d7bf 8.5%, transparent 8.5%)  30px 43px,
  linear-gradient(288deg, #e3d7bf 8.5%, transparent 8.5%) -70px 43px,
  linear-gradient(216deg, #e3d7bf 7.5%, transparent 7.5%) -70px 23px,
  linear-gradient(144deg, #e3d7bf 7.5%, transparent 7.5%)  30px 23px,
  linear-gradient(324deg, #232927 4%,   transparent 4%)   -20px 93px,
  linear-gradient( 36deg, #232927 4%,   transparent 4%)    80px 93px,
  linear-gradient( 72deg, #e3d7bf 8.5%, transparent 8.5%)  80px 93px,
  linear-gradient(288deg, #e3d7bf 8.5%, transparent 8.5%) -20px 93px,
  linear-gradient(216deg, #e3d7bf 7.5%, transparent 7.5%) -20px 73px,
  linear-gradient(144deg, #e3d7bf 7.5%, transparent 7.5%)  80px 73px !important;
  background-color: #232977 !important;
  background-size: 100px 100px !important;
}
/* STYLES TO CENTER A TEXT BLOCK ON A WHITE SEMI-TRANSPARENT BACKGROUND BLOCK */
/* White block div */
.blockdiv {
  color: black;
  font: 25px Arial, sans-serif !important;
  background: rgba(255,255,255,0.75);
  width: 100%;
  height: 30px;
}
/* Text container centered in .blockdiv */
.textdiv {
  position: relative;
  float: left;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</pre>
<p>To insert a static text element and its container, we can create a small JS routine that creates parent and child nodes that replace the panel&#8217;s title container:</p>
<pre lang="matlab">
% Make a nodeID string to make the JS call more generic
nodeID = sprintf('''[%s="%s"]''', panelID.ID_attr, panelID.ID_val);
% JS that creates a div within a div, each with their own classes
% The inner div gets the text and is centered within the outer div
% These elements are added before the node MATLAB will use for any controls
% added to scrollPane
js = sprintf( ...
  [ ...
    'var d = document.createElement("div");', ...
    'var t = document.createElement("div");', ...
    'd.classList.add("blockdiv");',...
    't.classList.add("textdiv");', ...
    't.innerHTML= "Some Static Text";', ...
    'd.appendChild(t);', ...
    'document.querySelectorAll(%s)[0]',...
    '.replaceChild(d,document.querySelectorAll(%s)[0].firstChild);' ...
  ], ...
  nodeID, nodeID ...
);
% execute the JS
webWindow.executeJS(js);
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_bgScroll.gif" alt="Panel background and static elements" title="Panel background and static elements" width="70%" style="max-width:450px;"/><!-- 566px --><br />
Panel background and static elements</center><br />
It seems to me that this approach might help to make lighter-weight apps, instead of having to make all those <i><b>app.Label</b></i> objects in Matlab&#8217;s App-Designer.</p>
<h3 id="Recap">Quick recap</h3>
<p>So let&#8217;s restate the process:</p>
<ol>
<li>Create a <i><b>uipanel</b></i> with the <b>Position</b> property set accordingly large enough for your control elements.</li>
<li>Use <code>mlapptools.setStyle()</code> to set the <a href="https://www.w3schools.com/css/css_overflow.asp" rel="nofollow" target="_blank"><code>overflow</code> style attribute</a> as desired.</li>
<li>Use <code>mlapptools.setStyle()</code> to set the <code>width</code> and/or <code>height</code> style attributes to the viewing size (this is how big the viewing area of the panel needs to be in order to fit nicely in your app).</li>
<li>Add your control elements with the scrolling <i><b>uipanel</b></i> as the parent.</li>
<li>If you want some special styles, create a stylesheet and inject it into the <code>&lt;head&gt;</code> and be sure to add the class to your panel&#8217;s HTML <code>classList</code>.</li>
</ol>
<p>The order of items 2-4 are not really important. You just need to ensure that the panel is large enough (via its <b>Position</b> property) to include all your elements/controls.<br />
I really hope that one day soon MathWorks will add CSS and JS hooks to <i><b>uifigure</b></i> GUI components (perhaps as settable <b>CSS</b>/<b>JS</b> properties that accept strings?), so that Matlab users could attach their own CSS and JS customizations directly within AppDesigner, without having to go through such undocumented hoops as I&#8217;ve shown here. In Loren Shure&#8217;s latest blog post, Matlab product manager <a href="https://blogs.mathworks.com/loren/2018/07/25/the-state-of-app-building-in-matlab/#573b536f-26bc-4a14-8d6b-38ed3c88b8d6" rel="nofollow" target="_blank">Dave Garisson indicated</a> that this is indeed planned for a near-future Matlab release (at least for JS, but hopefully also for CSS):</p>
<blockquote><p>&#8220;we are also investigating ways to provide a documented solution for integrating 3rd party JavaScript components in MATLAB apps.&#8221;</p></blockquote>
<h3 id="Example">A complete working example</h3>
<p>I created a complete working example in Matlab&#8217;s App Designer while figuring this whole thing out. The code (<i>CWE.m</i>) can be <a href="https://github.com/Khlick/matlabUiHacks/blob/master/scrollingUIPanel/CWE.m" rel="nofollow" target="_blank">downloaded here</a>, and then run directly from Matlab&#8217;s command window. Alternatively, the corresponding App Designer file (<i>CWE.mlapp</i>) can be <a href="https://github.com/Khlick/matlabUiHacks/blob/master/scrollingUIPanel/CWE.mlapp" rel="nofollow" target="_blank">downloaded here</a>. You are welcome to use/adapt the code in your own project. Just to be clear, I love wild colors and crazy themes, but I don&#8217;t recommend going this overboard for a real project.<br />
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_ADfig_1.png" alt="Running app demo" title="Running app demo" width="80%" style="max-width:804px;"/><br />
Running app demo</center><br />
<!--


<h3 id="hijack">Hijacking the uipanel altogether</h3>


In the previous example, we replaced the <code>&lt;div&gt;</code> container for the title part of the <i><b>uipanel</b></i>. We can insert other types of DOM nodes into the <i><b>uipanel</b></i> as well, for example a JS-generated table.
Every <i><b>uifigure</b></i> is essentially a web page running within a browser. Using JS, we can query the <a href="https://www.w3schools.com/js/js_window_navigator.asp" rel="nofollow" target="_blank"><code>navigator</code> object</a>, which contains a lot of information on the browser (<a href="http://help.dottoro.com/ljcsokrr.php" rel="nofollow" target="_blank">see here</a>). These <code>navigator</code> properties can be displayed in a JS-generated table within a Matlab <i><b>uipanel</b></i> (<a href="https://undocumentedmatlab.com/files/browserInfo.m" target="_blank">downloadable source code</a>):
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_matlabBrowserInfo.gif" alt="HTML table built with JS from the navigator object" title="HTML table built with JS from the navigator object" width="80%" style="max-width:700px;"/>
HTML table built with JS from the navigator object</center>
Note that these <code>navigator</code> properties correspond to my specific Matlab R2018a installation:


<pre lang="matlab">
>> version %MATLAB
    '9.4.0.813654 (R2018a)'
>> mlapptools.aboutJSLibs()  % display the loaded JS
  struct with fields:
        dojo: '1.11.2.91fa0cb'
    react_js: '0.14.7'
</pre>


--><br />
I can&#8217;t thank Yair enough for suggesting that I turn this tip into a guest post for you readers. And I want to give a huge thank you to you, the reader, for persevering all the way to the end of this post&#8230;<br />
Cheers!<br />
-Khris<br />
<b><u>Addendum September 17, 2018</u></b>: Scrolling panels in uifigures are now a fully-supported documented functionality via the new <a href="https://www.mathworks.com/help/matlab/ref/matlab.ui.container.tree.scroll.html" rel="nofollow" target="_blank"><i><b>scroll</b></i></a> function and <a href="https://www.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html#propname_Scrollable" rel="nofollow" target="_blank"><b>Scrollable</b></a> property, starting with Matlab release R2018b. You can still use the mechanism described above, which also works for older Matlab releases.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel">Customizing web-GUI uipanel</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-uipanels" rel="bookmark" title="Customizing Matlab uipanels">Customizing Matlab uipanels </a> <small>Matlab uipanel controls can be customized using Java in ways that are impossible with plain Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-3-backdrop" rel="bookmark" title="Customizing axes part 3 &#8211; Backdrop">Customizing axes part 3 &#8211; Backdrop </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing uifigures part 3</title>
		<link>https://undocumentedmatlab.com/articles/customizing-uifigures-part-3?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-uifigures-part-3</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-uifigures-part-3#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 27 Nov 2017 15:00:24 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Iliya Romm]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7169</guid>

					<description><![CDATA[<p>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent years). However, the exact mechanism by which the controls (&#8220;widgets&#8221;) are actually converted into visible [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3">Customizing uifigures part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based <a href="https://www.teamdev.com/jxbrowser" rel="nofollow" target="_blank">jxBrowser</a> in recent years). However, the exact mechanism by which the controls (&#8220;widgets&#8221;) are actually converted into visible components (currently based on the <a href="https://dojotoolkit.org" rel="nofollow" target="_blank">Dojo toolkit</a> and its Dijit UI library) and interact with Matlab (i.e., the internal Matlab class structures that interact with the browser and Dojo) is still undergoing changes and is not quite as stable.<br />
Customization hacks reported on this blog last year (<a href="/articles/customizing-uifigures-part-1" target="_blank">part 1</a>, <a href="/articles/customizing-uifigures-part-2" target="_blank">part 2</a>) may fail in some cases due to the changing nature of the undocumented internals. Some examples are the way by which we can extract the uifigure&#8217;s URL (which <a href="/articles/customizing-uifigures-part-2#comment-407215" target="_blank">changed in R2017a</a>), the ability to display and debug uifigures in a standard webbrowser with associated dev tools (which seems to have stopped working in R2017b), and the way by which we can extract the Dijit reference of displayed uicontrols.<br />
Greatly assisting in this respect is Iliya Romm, who was the guest blogger for <a href="/articles/customizing-uifigures-part-2" target="_blank">part 2</a> of this series last year. Iliya co-authored the open-source (GitHub) <a href="https://github.com/StackOverflowMATLABchat/mlapptools" rel="nofollow" target="_blank">mlapptools toolbox</a>, which enables accessing and customizing uifigure components using standard CSS, without users having to bother about the ugly hacks discussed in the previous parts of the series. This toolbox is really just a single Matlab class (<code>mlapptools</code>), contained within a single m-file (<i>mlapptools.m</i>). In addition to this class, the toolbox includes a <i>README.md</i> mark-down usage documentation, and two demo functions, <i>DOMdemoGUI.m</i> and <i>TableDemo.m</i>.<br />
Here is the effect of using <i>TableDemo</i>, that shows how we can customize individual uitable cells (each uitable cell is a separate Dijit widget that can be customized individually):<br />
<center><figure style="width: 363px" class="wp-caption aligncenter"><img decoding="async" alt="CSS customizations of uifigure components" src="https://undocumentedmatlab.com/images/uifigure_uitable_colors.png" title="CSS customizations of uifigure components" width="363" height="188" /><figcaption class="wp-caption-text">CSS customizations of uifigure components</figcaption></figure></center><br />
<span id="more-7169"></span><br />
The <i>mlapptools</i> class contains several static methods that can be used individually:</p>
<ul>
<li><i><b>textAlign</b>(uielement, alignment)</i> &#8211; Modify text horizontal alignment (<code>'left'</code>, <code>'center'</code>, <code>'right'</code>, <code>'justify'</code> or <code>'initial'</code>)</li>
<li><i><b>fontWeight</b>(uielement, weight)</i> &#8211; Modify font weight (<code>'normal'</code>, <code>'bold'</code>, <code>'bolder'</code>, <code>'lighter'</code> or <code>'initial'</code>), depending on availability in the font-face used</li>
<li><i><b>fontColor</b>(uielement, color)</i> &#8211; Modify font color (e.g. <code>'red'</code>, <code>'#ff0000'</code>, <code>'rgb(255,0,0)'</code> or <a href="https://www.w3.org/TR/css3-color/" rel="nofollow" target="_blank">other variants</a>)</li>
<li><i><b>setStyle</b>(uielement, styleAttr, styleValue)</i> &#8211; Modify a specified <a href="https://www.w3schools.com/cssref/" rel="nofollow" target="_blank">CSS style</a> attribute</li>
<li><i><b>aboutDojo</b>()</i> &#8211; Return version information about the Dojo toolkit</li>
<li><i><b>getHTML</b>(hFig)</i> &#8211; Return the full HTML code of a uifigure</li>
<li><i><b>getWebWindow</b>(hFig)</i> &#8211; Return a webwindow handle from a uifigure handle</li>
<li><i><b>getWebElements </b>(hControl)</i> &#8211; Return a webwindow handle and a widget ID for the specified uicontrol handle</li>
<li><i><b>getWidgetList</b>(hFig, verboseFlag)</i> &#8211; Return a cell-array of structs containing information about all widgets in the uifigure</li>
<li><i><b>getWidgetInfo</b>(hWebwindow, widgetId, verboseFlag)</i> &#8211; Return information about a specific dijit widget</li>
<li><i><b>setTimeout</b>(hFig, seconds)</i> &#8211; Override the default timeout (=5 secs) for dojo commands, for a specific uifigure</li>
</ul>
<p>A few simple usage examples:</p>
<pre lang="matlab">
mlapptools.fontColor(hButton,'red')  % set red text color
mlapptools.fontWeight(hButton,'bold')  % set bold text font
mlapptools.setStyle(hButton,'border','2px solid blue')  % add a 2-pixel solid blue border
mlapptools.setStyle(hButton,'background-image','url(https://www.mathworks.com/etc/designs/mathworks/img/pic-header-mathworks-logo.svg)')  % add background image
</pre>
<p>Once you download <i>mlapptools</i> and add its location to the Matlab path, you can use it in any web-based GUI that you create, either programmatically or with Add-Designer.<br />
The <i>mlapptools</i> is quite well written and documented, so if you are interested in the inner workings I urge you to take a look at this class&#8217;s private methods. For example, to understand how a Matlab uicontrol handle is converted into a Dojo widget-id, which is then used with the built-in <i>dojo.style()</i> Javascript function to modify the CSS attributes of the HTML <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code> that are the control&#8217;s visual representation on the webpage. An explanation of the underlying mechanism can be found in <a href="/articles/customizing-uifigures-part-2" target="_blank">part 2</a> of this series of articles on uifigure customizations. Note that the <i>mlapptools</i> code is newer than the article and contains some new concepts that were not covered in that article, for example searching through Dijit&#8217;s registry of displayed widgets.<br />
<b>Note</b>: web-based GUI is often referred to as &#8220;App-Designed&#8221; (AD) GUI, because using the Matlab App Designer is the typical way to create and customize such GUIs. However, just as great-looking GUIs could be created programmatically rather than with GUIDE, so too can web-based GUIS be created programmatically, using regular built-in Matlab commands such as <i><b>uifigure</b></i>, <i><b>uibutton</b></i> and <i><b>uitable</b></i> (an example of such programmatic GUI creation can be found in Iliya&#8217;s <i>TableDemo.m</i>, discussed above). For this reason, I believe that the new GUIs should be referred to as &#8220;uifigures&#8221; or &#8220;web GUIs&#8221;, and not as &#8220;AD GUIs&#8221;.<br />
If you have any feature requests or bugs related to <i>mlapptools</i>, please report them on its <a href="https://github.com/StackOverflowMATLABchat/mlapptools/issues" rel="nofollow" target="_blank">GitHub issues page</a>. For anything else, please add a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3">Customizing uifigures part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-uifigures-part-3/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</title>
		<link>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-gui-training-seminars-zurich-29-30-august-2017</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 04 Aug 2017 09:37:52 +0000</pubDate>
				<category><![CDATA[Public presentation]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6992</guid>

					<description><![CDATA[<p>Advanced Matlab training courses on Matlab User Interfaces (GUI) will be presented in Zurich Switzerland on 29-30 August, 2017</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><span class="alignright"><img loading="lazy" decoding="async" alt="Advanced Matlab training, Zurich 29-30 August 2017" src="https://undocumentedmatlab.com/images/20140520_153734a_500x321.jpg" title="Advanced Matlab training, Zurich 29-30 August 2017" width="400" height="257"/></span><br />
Advanced Matlab training courses/seminars will be presented by me (Yair) in Zürich, Switzerland on 29-30 August, 2017:</p>
<ul>
<li>August 29 (full day) &#8211; <b>Interactive Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --></p>
<li>August 30 (full day) &#8211; <b>Advanced Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --><br />
	<!-- li>Enroll to both courses (2 full days) for a total price of US$699 (CHF 680.-)</li --> <!-- ($150 extra discount if paid by July 31) -->
</ul>
<p><!-- b>Both seminars are confirmed</b>: they do not depend on a minimal number of participants. But there is a limit on the total number of participants, so the sooner you enroll, the more likely you are to get a seat. --><br />
The seminars are targeted at Matlab users who wish to improve their program&#8217;s usability and professional appearance. Basic familiarity with the Matlab environment and coding/programming is assumed. The courses will present a mix of both documented and undocumented aspects, which is not available anywhere else. The curriculum is listed below.<br />
This is a unique opportunity to enhance your Matlab coding skills and improve your program&#8217;s usability in a couple of days<!-- , at a very affordable cost -->.<br />
If you are interested in either or both of these seminars, please <a href="mailto:%20altmany%20@gmail.com?subject=Matlab%20training%20Zurich&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=Matlab training Zurich&amp;body=Hi Yair, '); return false;">Email me</a> (altmany at gmail dot com).<br />
I can also schedule a dedicated visit to your location, for onsite Matlab training customized to your organization&#8217;s specific needs. Additional information can be found on my <a target="_blank" href="/training/">Training page</a>.<br />
Around the time of the training, I will be traveling to various locations around Switzerland. <!-- in Geneva (Aug 22-27), Bern (Aug 27-28), Zürich (Aug 28-30), and Basel (Aug 30 - Sep 3) --> If you wish to meet me in person to discuss how I could bring value to your project, then please email me (altmany at gmail):</p>
<ul>
<li>Geneva: Aug 22 &#8211; 27</li>
<li>Bern: Aug 27 &#8211; 28</li>
<li>Zürich: Aug 28 &#8211; 30</li>
<li>Stuttgart: Aug 30 &#8211; 31</li>
<li>Basel: Sep 1 &#8211; 3</li>
</ul>
<p><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/email-icon.png" width="32" height="22" alt="" style="vertical-align:middle;border:0"/>&nbsp;<a href="mailto: altmany @gmail.com?subject=Matlab consulting/training&#038;body=Hi Yair, &#038;cc=;&#038;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab consulting/training&#038;body=Hi Yair, '); return false;">Email me</a><br />
<span id="more-6992"></span></p>
<hr/>
<h3 id="GUI">Interactive Matlab GUI &#8211; 29 August, 2017</h3>
<ol>
<li>Introduction to Matlab Graphical User Interfaces (GUI)
<ul>
<li>Design principles and best practices</li>
<li>Matlab GUI alternatives</li>
<li>Typical evolution of Matlab GUI developers</li>
</ul>
</li>
<li>GUIDE – MATLAB&#8217;s GUI Design Editor
<ul>
<li>Using GUIDE to design a custom GUI</li>
<li>Available built-in MATLAB uicontrols</li>
<li>Customizing uicontrols</li>
<li>Important figure and uicontrol properties</li>
<li>GUIDE utility windows</li>
<li>The GUIDE-generated file-duo</li>
</ul>
</li>
<li>Customizing GUI appearance and behavior
<ul>
<li>Programmatic GUI creation and control</li>
<li>GUIDE vs. m-programming</li>
<li>Attaching callback functionality to GUI components</li>
<li>Sharing data between GUI components</li>
<li>The handles data struct</li>
<li>Using handle visibility</li>
<li>Position, size and units</li>
<li>Formatting GUI using HTML</li>
</ul>
</li>
<li>Uitable
<ul>
<li>Displaying data in a MATLAB GUI uitable</li>
<li>Controlling column data type</li>
<li>Customizing uitable appearance</li>
<li>Reading uitable data</li>
<li>Uitable callbacks</li>
<li>Additional customizations using Java</li>
</ul>
</li>
<li>Matlab&#8217;s new App Designer and web-based GUI
<ul>
<li>App Designer environment, widgets and code</li>
<li>The web-based future of Matlab GUI and assumed roadmap</li>
<li>App Designer vs. GUIDE – pros and cons comparison</li>
</ul>
</li>
<li>Performance and interactivity considerations
<ul>
<li>Speeding up the initial GUI generation</li>
<li>Improving GUI responsiveness</li>
<li>Actual vs. perceived performance</li>
<li>Continuous interface feedback</li>
<li>Avoiding common performance pitfalls</li>
<li>Tradeoff considerations</li>
</ul>
</li>
</ol>
<p><!-- Throughout the day, a sample data-structure container class will be developed and presented in phases, illustrating the points discussed in the presentation, along with suggestions and discussion on design alternatives, programming quality, efficiency, robustness, maintainability, and performance. In other words, the seminar will include not just a formal presentation of the material but also a live annotated development of a real-world Matlab class that illustrates the presented topics. --><br />
At the end of this seminar, you will have learned how to:</p>
<ul>
<li>apply GUI design principles in Matlab</li>
<li>create simple Matlab GUIs</li>
<li>manipulate and customize graphs, images and GUI components</li>
<li>display Matlab data in a variety of GUI manners, including data tables</li>
<li>decide between using GUIDE, App Designer and/or programmatic GUI</li>
<li>understand tradeoffs in design and run-time performance</li>
<li>comprehend performance implications, to improve GUI speed and responsiveness</li>
</ul>
<hr/>
<h3 id="AMG">Advanced Matlab GUI &#8211; 30 August, 2017</h3>
<ol>
<li>Advanced topics in Matlab GUI
<ul>
<li>GUI callback interrupts and re-entrancy</li>
<li>GUI units and resizing</li>
<li>Advanced HTML formatting</li>
<li>Using hidden (undocumented) properties</li>
<li>Listening to action and property-change events</li>
<li>Uitab, uitree, uiundo and other uitools</li>
</ul>
</li>
<li>Customizing the figure window
<ul>
<li>Creating and customizing the figure&#8217;s main menu</li>
<li>Creating and using context menus</li>
<li>Creating and customizing figure toolbars</li>
</ul>
</li>
<li>Using Java with Matlab GUI
<ul>
<li>Matlab and Java Swing</li>
<li>Integrating Java controls in Matlab GUI</li>
<li>Handling Java events as Matlab callbacks</li>
<li>Integrating built-in Matlab controls/widgets</li>
<li>Integrating JIDE&#8217;s advanced features and professional controls</li>
<li>Integrating 3rd-party Java components: charts/graphs/widgets/reports</li>
</ul>
</li>
<li>Advanced Matlab-Java GUI
<ul>
<li>Customizing standard Matlab uicontrols</li>
<li>Figure-level customization (maximize/minimize, disable etc.)</li>
<li>Containers and position – Matlab vs. Java</li>
<li>Compatibility aspects and trade-offs</li>
<li>Safe programming with Java in Matlab</li>
<li>Java&#8217;s EDT and timing considerations</li>
<li>Deployment (compiler) aspects</li>
</ul>
</li>
</ol>
<p>At the end of this seminar, you will have learned how to:</p>
<ul>
<li>customize the figure toolbar and main menu</li>
<li>use HTML to format GUI appearance</li>
<li>integrate Java controls in Matlab GUI</li>
<li>customize your Matlab GUI to a degree that you never knew was possible</li>
<li>create a modern-looking professional GUI in Matlab</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;s underlying Java object </a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MathWorks-solicited Java survey</title>
		<link>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mathworks-solicited-java-survey</link>
					<comments>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 22 Mar 2017 22:05:34 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[uifigure]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6866</guid>

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

					<description><![CDATA[<p>Password fields and spinner controls can easily be embedded in Matlab GUIs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/password-and-spinner-controls-in-matlab-gui">Password &amp; spinner controls in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-7-selection-controls" rel="bookmark" title="Matlab toolstrip – part 7 (selection controls)">Matlab toolstrip – part 7 (selection controls) </a> <small>Matlab toolstrips can contain a wide variety of selection controls: popups, combo-boxes, and galleries. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-6-complex-controls" rel="bookmark" title="Matlab toolstrip – part 6 (complex controls)">Matlab toolstrip – part 6 (complex controls) </a> <small>Multiple types of customizable controls can be added to Matlab toolstrips...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/reverting-axes-controls-in-figure-toolbar" rel="bookmark" title="Reverting axes controls in figure toolbar">Reverting axes controls in figure toolbar </a> <small>In R2018b the axes controls were removed from the figure toolbar, but this can be reverted. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I often include configuration panels in my programs, to enable the user to configure various program aspects, such as which emails should automatically be sent by the program to alert when certain conditions occur. Last week <a href="/articles/sending-email-text-messages-from-matlab" target="_blank">I presented</a> such a configuration panel, which is mainly composed of standard documented Matlab controls (sub-panels, uitables and uicontrols). As promised, today&#8217;s post will discuss two undocumented controls that are often useful in similar configuration panels (not necessarily for emails): password fields and spinners.<br />
<center><a href="/images/email_config_panel.png" target="_blank"><img decoding="async" alt="Matlab GUI configuration panel including password and spinner controls (click to zoom-in)" src="https://undocumentedmatlab.com/images/email_config_panel.png" title="Matlab GUI configuration panel including password and spinner controls (click to zoom-in)" width="75%" style="max-width:842px;"></a><br />
Matlab GUI configuration panel including password and spinner controls (click to zoom-in)</center><br />
Password fields are basically editboxes that hide the typed text with some generic echo character (such as * or a bullet); spinners are editboxes that only enable typing certain preconfigured values (e.g., numbers in a certain range). Both controls are part of the standard Java Swing package, on which the current (non-web-based) Matlab GUIs relies. In both cases, we can use the <a href="/articles/javacomponent" target="_blank"><i><b>javacomponent</b></i> function</a> to place the built-in Swing component in our Matlab GUI.<br />
<span id="more-6775"></span></p>
<h3 id="password">Password field</h3>
<p>The relevant Java Swing control for password fields is <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/passwordfield.html"><code>javax.swing.JPasswordField</code></a>. <code>JPasswordField</code> is basically an editbox that hides any typed key with a * or bullet character.<br />
Here&#8217;s a basic code snippet showing how to display a simple password field:</p>
<pre lang='matlab'>
jPasswordField = javax.swing.JPasswordField('defaultPassword');  % default password arg is optional
jPasswordField = javaObjectEDT(jPasswordField);  % javaObjectEDT is optional but recommended to avoid timing-related GUI issues
jhPasswordField = javacomponent(jPasswordField, [10,10,70,20], gcf);
</pre>
<p><center><figure style="width: 105px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Password control" src="https://undocumentedmatlab.com/images/JPasswordField.gif" title="Password control" width="105" height="30" /><figcaption class="wp-caption-text">Password control</figcaption></figure></center><br />
We can set/get the password string programmatically via the <b>Text</b> property; the displayed (echo) character can be set/get using the <b>EchoChar</b> property.<br />
To attach a data-change callback, set jhPasswordField&#8217;s <b>ActionPerformedCallback</b> property.</p>
<h3 id="spinner">Spinner control</h3>
<p><a href="/articles/using-spinners-in-matlab-gui" target="_blank">detailed post on using spinners in Matlab GUI</a><br />
The relevant Java Swing control for spinners is <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html"><code>javax.swing.JSpinner</code></a>. <code>JSpinner</code> is basically an editbox with two tiny adjacent up/down buttons that visually emulate a small round spinning knob. Spinners are similar in functionality to a combo-box (a.k.a. drop-down or pop-up menu), where a user can switch between several pre-selected values. They are often used when the list of possible values is too large to display in a combo-box menu. Like combo-boxes, spinners too can be editable (meaning that the user can type a value in the editbox) or not (the user can only &#8220;spin&#8221; the value using the up/down buttons).<br />
<code>JSpinner</code> uses an internal data model. The default model is <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/SpinnerNumberModel.html"><code>SpinnerNumberModel</code></a>, which defines a min/max value (unlimited=[] by default) and step-size (1 by default). Additional predefined models are <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/SpinnerListModel.html"><code>SpinnerListModel</code></a> (which accepts a cell array of possible string values) and <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/SpinnerDateModel.html"><code>SpinnerDateModel</code></a> (which defines a date range and step unit).<br />
Here&#8217;s a basic code snippet showing how to display a simple numeric spinner for numbers between 20 and 35, with an initial value of 24 and increments of 0.1:</p>
<pre lang='matlab'>
jModel = javax.swing.SpinnerNumberModel(24,20,35,0.1);
jSpinner = javax.swing.JSpinner(jModel);
jSpinner = javaObjectEDT(jSpinner);  % javaObjectEDT is optional but recommended to avoid timing-related GUI issues
jhSpinner = javacomponent(jSpinner, [10,10,70,20], gcf);
</pre>
<p>The spinner value can be set using the edit-box or by clicking on one of the tiny arrow buttons, or programmatically by setting the <b>Value</b> property. The spinner object also has related read-only properties <b>NextValue</b> and <b>PreviousValue</b>. The spinner&#8217;s model object has the corresponding <b>Value</b> (settable), <b>NextValue</b> (read-only) and <b>PreviousValue</b> (read-only) properties. In addition, the various models have specific properties. For example, <code>SpinnerNumberModel</code> has the settable <b>Maximum</b>, <b>Minimum</b> and <b>StepSize</b> properties.<br />
To attach a data-change callback, set jhSpinner&#8217;s <b>StateChangedCallback</b> property.<br />
I have created a small Matlab demo, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/26970-spinnerdemo"><i><b>SpinnerDemo</b></i></a>,  which demonstrates usage of <code>JSpinner</code> in Matlab figures. Each of the three predefined models (number, list, and date) is presented, and the spinner values are inter-connected via their callbacks. The Matlab code is modeled after the <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/examples/components/SpinnerDemoProject/src/components/SpinnerDemo.java">Java code</a> that is used to document <code>JSpinner</code> in the official Java documentation. Readers are welcome to download this demo from the Matlab File Exchange and reuse its source code.<br />
<center><figure style="width: 188px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab SpinnerDemo" src="https://undocumentedmatlab.com/images/SpinnerDemoMatlab.png" title="Matlab SpinnerDemo" width="188" height="184"/><figcaption class="wp-caption-text">Matlab SpinnerDemo</figcaption></figure></center><br />
The nice thing about spinners is that you can set a custom display format without affecting the underlying data model. For example, the following code snippet update the spinner&#8217;s display format without affecting its underlying numeric data model:</p>
<pre lang="matlab">
formatStr = '$ #,##0.0 Bn';
jEditor = javaObject('javax.swing.JSpinner$NumberEditor', jhSpinner, formatStr);
jhSpinner.setEditor(jEditor);
</pre>
<p><center><figure style="width: 105px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Formatted spinner control" src="https://undocumentedmatlab.com/images/JSpinner.gif" title="Formatted spinner control" width="105" height="30" /><figcaption class="wp-caption-text">Formatted spinner control</figcaption></figure></center><br />
For more information, refer to my <a href="/articles/using-spinners-in-matlab-gui" target="_blank">detailed post on using spinners in Matlab GUI</a>.</p>
<h3 id="warning">Caveat emptor</h3>
<p>MathWorks&#8217; new web-based GUI paradigm will most probably not directly support the Java components presented in today&#8217;s post, or more specifically the <i><b>javacomponent</b></i> function that enables placing them in Matlab GUIs. The new web-based GUI-building application (<a href="https://www.mathworks.com/products/matlab/app-designer.html" rel="nofollow" target="_blank">AppDesigner</a>, aka AD) does contain a spinner, although it is [currently] limited to displaying numeric values (not dates/lists as in my SpinnerDemo). Password fields are not currently supported by AppDesigner at all, and it is unknown whether they will ever be.<br />
All this means that users of Java controls who wish to transition to the new web-based GUIs will need to develop <a href="/articles/editbox-data-input-validation" rel="nofollow" target="_blank">programmatic workarounds</a>, that would presumably appear and behave less professional. It&#8217;s a tradeoff: AppDesigner does include features that improve GUI usability, not to mention the presumed future ability to post Matlab GUIs online (hopefully without requiring a monstrous Matlab Production Server license/installation).<br />
In the past, MathWorks has posted a <a href="http://www.mathworks.com/support/contact_us/dev/javaframe.html" rel="nofollow" target="_blank">dedicated webpage</a> to solicit user feedback on how they are using the figure&#8217;s <b>JavaFrame</b> property. MathWorks will presumably prepare a similar webpage to solicit user feedback on uses of the <i><b>javacomponent</b></i> function, so they could add the top items to AppDesigner, making the transition to web-based GUIs less painful. When such a survey page becomes live, I will post about it on this website so that you could tell MathWorks about your specific use-cases and help them prioritize their R&#038;D efforts.<br />
In any case, regardless of whether the functionality eventually makes it into AppDesigner, my hope is that when the time comes MathWorks will not pull the plug from non-web GUIs, and will still enable running them on desktops for backward compatibility (&#8220;legacy mode&#8221;). Users of existing GUIs will then not need to choose between upgrading their Matlab (and redeveloping their GUI as a web-based app) and running their existing programs. Instead, users will face the much less painful choice between keeping the existing Java-based programs and developing a web-based variant at some later time, separate from the choice of whether or not to upgrade Matlab. The increased revenue from license upgrades and SMS (maintenance plan) renewals might well offset the R&#038;D effort that would be needed to keep supporting the old Java-based figures. The traumatic<sup>*</sup> release of HG2 in R2014b, where a less-than-perfect version was released with no legacy mode, resulting in significant user backlash/disappointment, is hopefully still fresh in the memory of decision makers and would hopefully not be repeated.<br />
<sup>*</sup><i>well, traumatic for some at least. I really don&#8217;t wish to make this a debate on HG2&#8217;s release; I&#8217;d rather focus on making the transition to web-based GUIs as seamless as possible.</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/password-and-spinner-controls-in-matlab-gui">Password &amp; spinner controls in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-7-selection-controls" rel="bookmark" title="Matlab toolstrip – part 7 (selection controls)">Matlab toolstrip – part 7 (selection controls) </a> <small>Matlab toolstrips can contain a wide variety of selection controls: popups, combo-boxes, and galleries. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-6-complex-controls" rel="bookmark" title="Matlab toolstrip – part 6 (complex controls)">Matlab toolstrip – part 6 (complex controls) </a> <small>Multiple types of customizable controls can be added to Matlab toolstrips...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/reverting-axes-controls-in-figure-toolbar" rel="bookmark" title="Reverting axes controls in figure toolbar">Reverting axes controls in figure toolbar </a> <small>In R2018b the axes controls were removed from the figure toolbar, but this can be reverted. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/password-and-spinner-controls-in-matlab-gui/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>AppDesigner&#039;s mlapp file format</title>
		<link>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=appdesigner-mlapp-file-format</link>
					<comments>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 17 Aug 2016 17:00:04 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6613</guid>

					<description><![CDATA[<p>MLAPP files created by AppDesigner can be inspected and manipulated outside AppDesigner. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format">AppDesigner&#039;s mlapp file format</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/mlintfailurefiles" rel="bookmark" title="MLintFailureFiles or: Why can&#039;t I save my m-file?!">MLintFailureFiles or: Why can&#039;t I save my m-file?! </a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-axes-tick-labels-format" rel="bookmark" title="Setting axes tick labels format">Setting axes tick labels format </a> <small>Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance" rel="bookmark" title="File deletion memory leaks, performance">File deletion memory leaks, performance </a> <small>Matlab's delete function leaks memory and is also slower than the equivalent Java function. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Six years ago, I exposed the fact that <a href="/articles/fig-files-format" rel="nofollow" target="_blank">*.fig files are simply MAT files in disguise</a>. This information, in addition to the data format that I explained in that article, can help us to introspect and modify FIG files without having to actually display the figure onscreen.<br />
Matlab has changed significantly since 2010, and one of the exciting new additions is the <a href="/articles/sliders-in-matlab-gui#AppDesigner" rel="nofollow" target="_blank">AppDesigner</a>, Matlab&#8217;s new GUI layout designer/editor. Unfortunately, AppDesigner still has quite a few limitations in functionality and behavior. I expect that this will improve in upcoming releases since AppDesigner is undergoing active development. But in the meantime, it makes sense to see whether we could directly introspect and potentially manipulate AppDesigner&#8217;s output (*.mlapp files), as we could with GUIDE&#8217;s output (*.fig files).<br />
A situation for checking this was recently raised by a reader on the Answers forum: apparently <a href="https://www.mathworks.com/matlabcentral/answers/279042-app-designer-s-editor-is-slow-and-gets-stuck-alot" rel="nofollow" target="_blank">AppDesigner becomes increasingly sluggish</a> when the figure&#8217;s code has more than a few hundred lines of code (i.e., a very simplistic GUI). In today&#8217;s post I intend to show how we can explore the resulting *.mlapp file, and possibly manipulate it in a text editor outside AppDesigner.<br />
<center><figure style="width: 598px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's new AppDesigner (a somewhat outdated screenshot)" src="https://undocumentedmatlab.com/images/slider_AppDesigner.png" title="Matlab's new AppDesigner (a somewhat outdated screenshot)" width="598" height="376" /><figcaption class="wp-caption-text">Matlab's new AppDesigner (a somewhat outdated screenshot)</figcaption></figure></center><br />
<span id="more-6613"></span></p>
<h3 id="format">The MLAPP file format</h3>
<p>Apparently, *.mlapp files are simply ZIP files in disguise (note: not MAT files as for *.fig files). A typical MLAPP&#8217;s zipped contents contains the following files (note that this might be a bit different on different Matlab releases):</p>
<ul>
<li><i>[Content_Types].xml</i> &#8211; this seems to be application-independent:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
   <default Extension="mat" ContentType="application/vnd.mathworks.matlab.appDesigner.appModel+mat"/>
   <default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
   <default Extension="xml" ContentType="application/vnd.mathworks.matlab.code.document+xml;plaincode=true"/>
   <override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/metadata/coreProperties.xml"/>
   <override ContentType="application/vnd.mathworks.package.coreProperties+xml" PartName="/metadata/mwcoreProperties.xml"/>
   <override ContentType="application/vnd.mathworks.package.corePropertiesExtension+xml" PartName="/metadata/mwcorePropertiesExtension.xml"/>
</types>
</pre>
</li>
<li><i>_rels/.rels</i> &#8211; also application-independent:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
   <relationship Type="http://schemas.mathworks.com/matlab/code/2013/relationships/document" Target="matlab/document.xml" Id="rId1"/>
   <relationship Type="http://schemas.mathworks.com/package/2012/relationships/coreProperties" Target="metadata/mwcoreProperties.xml" Id="rId2"/>
   <relationship Type="http://schemas.mathworks.com/package/2014/relationships/corePropertiesExtension" Target="metadata/mwcorePropertiesExtension.xml" Id="rId3"/>
   <relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="metadata/coreProperties.xml" Id="rId4"/>
   <relationship Type="http://schemas.mathworks.com/appDesigner/app/2014/relationships/appModel" Target="appdesigner/appModel.mat" Id="rId5"/>
</relationships>
</pre>
</li>
<li><i>metadata/coreProperties.xml</i> &#8211; contains the timestamp of figure creation and last update:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<cp:coreProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
   <dcterms:created xsi:type="dcterms:W3CDTF">2016-08-01T18:20:26Z</dcterms:created>
   <dcterms:modified xsi:type="dcterms:W3CDTF">2016-08-01T18:20:27Z</dcterms:modified>
</cp:coreProperties>
</pre>
</li>
<li><i>metadata/mwcoreProperties.xml</i> &#8211; contains information on the generating Matlab release:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<mwcoreProperties xmlns="http://schemas.mathworks.com/package/2012/coreProperties">
   <contentType>application/vnd.mathworks.matlab.app</contentType>
   <contentTypeFriendlyName>MATLAB App</contentTypeFriendlyName>
   <matlabRelease>R2016a</matlabRelease>
</mwcoreProperties>
</pre>
</li>
<li><i>metadata/mwcorePropertiesExtension.xml</i> &#8211; more information about the generating Matlab release. Note that the version number is not exactly the same as the main Matlab version number: here we have 9.0.0.328027 whereas the main Matlab version number is 9.0.0.341360. I do not know whether this is checked anywhere.
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<mwcoreProperties xmlns="http://schemas.mathworks.com/package/2014/corePropertiesExtension">
   <matlabVersion>9.0.0.328027</matlabVersion>
</mwcoreProperties>
</pre>
</li>
<li><i>appdesigner/appModel.mat</i> &#8211; This is a simple MAT file that holds a single Matlab object called &#8220;appData&#8221; (of type <code>appdesigner.internal.serialization.app.AppData</code>)  the information about the <i><b>uifigure</b></i>, similar in concept to the <i>*.fig</i> files generated by the old GUIDE:
<pre lang="matlab">
>> d = load('C:\Yair\App3\appdesigner\appModel.mat')
Warning: Functionality not supported with figures created with the uifigure function. For more information,
see Graphics Support in App Designer.
(Type "warning off MATLAB:ui:uifigure:UnsupportedAppDesignerFunctionality" to suppress this warning.)
d =
    appData: [1x1 appdesigner.internal.serialization.app.AppData]
>> d.appData
ans =
  AppData with properties:
      UIFigure: [1x1 Figure]
      CodeData: [1x1 appdesigner.internal.codegeneration.model.CodeData]
      Metadata: [1x1 appdesigner.internal.serialization.app.AppMetadata]
    ToolboxVer: '2016a'
>> d.appData.CodeData
ans =
  CodeData with properties:
    GeneratedClassName: 'App3'
             Callbacks: [0x0 appdesigner.internal.codegeneration.model.AppCallback]
            StartupFcn: [1x1 appdesigner.internal.codegeneration.model.AppCallback]
       EditableSection: [1x1 appdesigner.internal.codegeneration.model.CodeSection]
            ToolboxVer: '2016a'
>> d.appData.Metadata
ans =
  AppMetadata with properties:
    GroupHierarchy: {}
        ToolboxVer: '2016a'
</pre>
</li>
<li><i>matlab/document.xml</i> &#8211; this file contains a copy of the figure&#8217;s classdef code in plain-text XML:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
   <w:body>
      <w:p>
         <w:pPr>
            <w:pStyle w:val="code"/>
         </w:pPr>
         <w:r>
            <w:t>
               <![CDATA[classdef App2 < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure UIAxes matlab.ui.control.UIAxes Button matlab.ui.control.Button CheckBox matlab.ui.control.CheckBox ListBoxLabel matlab.ui.control.Label ListBox matlab.ui.control.ListBox end methods (Access = public) function results = func(app) % Yair 1/8/2016 end end % App initialization and construction methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure app.UIFigure = uifigure; app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; setAutoResize(app, app.UIFigure, true) % Create UIAxes app.UIAxes = uiaxes(app.UIFigure); title(app.UIAxes, 'Axes'); xlabel(app.UIAxes, 'X'); ylabel(app.UIAxes, 'Y'); app.UIAxes.Position = [23 273 300 185]; % Create Button app.Button = uibutton(app.UIFigure, 'push'); app.Button.Position = [491 378 100 22]; % Create CheckBox app.CheckBox = uicheckbox(app.UIFigure); app.CheckBox.Position = [491 304 76 15]; % Create ListBoxLabel app.ListBoxLabel = uilabel(app.UIFigure); app.ListBoxLabel.HorizontalAlignment = 'right'; app.ListBoxLabel.Position = [359 260 43 15]; app.ListBoxLabel.Text = 'List Box'; % Create ListBox app.ListBox = uilistbox(app.UIFigure); app.ListBox.Position = [417 203 100 74]; end end methods (Access = public) % Construct app function app = App2() % Create and configure components createComponents(app) % Register the app with App Designer registerApp(app, app.UIFigure) if nargout == 0 clear app end end % Code that executes before app deletion function delete(app) % Delete UIFigure when app is deleted delete(app.UIFigure) end end end]]&gt;
            </w:t>
         </w:r>
      </w:p>
   </w:body>
</w:document>
</pre>
</li>
</ul>
<p>I do not know why the code is duplicated, both in <i>document.xml</i> and (twice!) in <i>appModel.mat</i>. On the face of it, this does not seem to be a wise design decision.</p>
<h3 id="editing">Editing MLAPP files outside AppDesigner</h3>
<p>We can presumably edit the app in an external editor as follow:</p>
<ol>
<li>Open the <i>*.mlapp</i> file in your favorite zip viewer (e.g., winzip or winrar). You may need to rename/copy the file as <i>*.zip</i>.</li>
<li>Edit the contents of the contained <i>matlab/document.xml</i> file in your favorite text editor (Matlab&#8217;s editor for example)</li>
<li>Load <i>appdesigner/appModel.mat</i> into Matlab workspace.</li>
<li>Go to <code>appData.CodeData.EditableSection.Code</code> and update the cell array with the lines of your updated code (one cell element per user-code line).</li>
<li>Do the same with <code>appData.CodeData.GeneratedCode</code> (if existing), which holds the same data as <code>appData.CodeData.EditableSection.Code</code> but also including the AppDesigner-generated [non-editable] code.</li>
<li>Save the modified appData struct back into <i>appdesigner/appModel.mat</i></li>
<li>Update the zip file (<i>*.mlapp</i>) with the updated <i>appModel.mat</i> and <i>document.xml</i></li>
</ol>
<p>In theory, it is enough to extract the classdef code and same it in a simple <i>*.m</i> file, but then you would not be able to continue using AppDesigner to make layout modifications, and you would need to make all the changes manually in the m-file. If you wish to continue using AppDesigner after you modified the code, then you need to save it back into the <i>*.mlapp</i> file as explained above.<br />
If you think this is not worth all the effort, then you&#8217;re probably right. But you must admit that it&#8217;s a bit fun to poke around&#8230;<br />
One day maybe I&#8217;ll create wrapper utilities (<i><b>mlapp2m</b></i> and <i><b>m2mlapp</b></i>) that do all this automatically, in both directions. Or maybe one of my readers here will pick up the glove and do it sooner &#8211; are you up for the challenge?</p>
<h3 id="caveat">Caveat Emptor</h3>
<p>Note that the MLAPP file format is deeply undocumented and subject to change without prior notice in upcoming Matlab releases. In fact, MathWorker Chris Portal <a href="https://www.mathworks.com/matlabcentral/answers/279042#comment_383621" rel="nofollow" target="_blank">warns us</a> that:</p>
<blockquote><p>A word of caution for anyone that tries this undocumented/unsupported poking into their MLAPP file. Taking this approach will almost certainly guarantee your app to not load in one of the subsequent releases. Just something to consider in your off-roading expedition!</p></blockquote>
<p>Then again, the same could have been said about the FIG and other binary file formats used by Matlab, which remained essentially the same for the past decade: Some internal field values may have changed but not the general format, and in any case the newer releases still accept files created with previous releases. For this reason, I speculate that future AppDesigners will accept MLAPP files created by older releases, possibly even hand-modified MLAPP files. Perhaps a CRC hash code of some sort will be expected, but I believe that any MLAPP that we modify today will still work in future releases. However, I could well be mistaken, so please be very careful with this knowledge. I trust that you can make up your own mind about whether it is worth the risk (and fun) or not.<br />
AppDesigner is destined to gradually replace the aging GUIDE over the upcoming years. They currently coexist since AppDesigner (and its web-based uifigures) still does not contain all the functionality that GUIDE (and JFrame-based figures) provides (<a href="/articles/customizing-uifigures-part-1#comment-384672" rel="nofollow" target="_blank">a few examples</a>). I already posted a few short posts about AppDesigner (use the <a href="/articles/tag/appdesigner" rel="nofollow" target="_blank">AppDesigner tag</a> to list them), and today&#8217;s article is another in that series. Over the next few years I intend to publish more on AppDesigner and its associated new GUI framework (<a href="/articles/tag/uifigure" rel="nofollow" target="_blank">uifigures</a>).</p>
<h3 id="Zurich">Zurich visit, 21-31 Aug 2016</h3>
<p>I will be traveling to Zürich for a business trip between August 21-31. If you are in the Zürich area and wish to meet me to discuss how I could bring value to your work, then please email me (altmany at gmail).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format">AppDesigner&#039;s mlapp file format</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/mlintfailurefiles" rel="bookmark" title="MLintFailureFiles or: Why can&#039;t I save my m-file?!">MLintFailureFiles or: Why can&#039;t I save my m-file?! </a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-axes-tick-labels-format" rel="bookmark" title="Setting axes tick labels format">Setting axes tick labels format </a> <small>Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance" rel="bookmark" title="File deletion memory leaks, performance">File deletion memory leaks, performance </a> <small>Matlab's delete function leaks memory and is also slower than the equivalent Java function. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing uifigures part 1</title>
		<link>https://undocumentedmatlab.com/articles/customizing-uifigures-part-1?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-uifigures-part-1</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-uifigures-part-1#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 21 Jul 2016 10:32:51 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6554</guid>

					<description><![CDATA[<p>Matlab's new web-based  uifigures can be customized in a variety of undocumented ways. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1">Customizing uifigures part 1</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-print-setup" rel="bookmark" title="Customizing print setup">Customizing print setup </a> <small>Matlab figures print-setup can be customized to automatically prepare the figure for printing in a specific configuration...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last month, I posted an article that summarized a variety of undocumented <a href="/articles/figure-window-customizations" target="_blank">customizations to Matlab figure windows</a>. As I noted in that post, Matlab figures have used Java <code>JFrame</code>s as their underlying technology since R14 (over a decade ago), but this is expected to change a few years from now with the advent of web-based <i><b>uifigure</b></i>s. <i><b>uifigure</b></i>s first became available in late 2014 with the new <a href="/articles/sliders-in-matlab-gui#AppDesigner" target="_blank">App Designer preview</a> (the much-awaited GUIDE replacement), and were <a href="http://www.mathworks.com/products/matlab/app-designer/" rel="nofollow" target="_blank">officially released in R2016a</a>. AppDesigner is actively being developed and we should expect to see exciting new features in upcoming Matlab releases.<br />
<center><figure style="width: 598px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's new AppDesigner (a somewhat outdated screenshot)" src="https://undocumentedmatlab.com/images/slider_AppDesigner.png" title="Matlab's new AppDesigner (a somewhat outdated screenshot)" width="598" height="376" /><figcaption class="wp-caption-text">Matlab's new AppDesigner (a somewhat outdated screenshot)</figcaption></figure></center><br />
However, while AppDesigner has become officially supported, the underlying technology used for the new <i><b>uifigure</b></i>s remained undocumented. <span id="more-6554"></span>This is not surprising: MathWorks did a good job of retaining backward compatibility with the existing <i><b>figure</b></i> handle, and so a new <i><b>uifigure</b></i> returns a handle that programmatically appears similar to <i><b>figure</b></i> handles, reducing the migration cost when MathWorks decides (<a href="/articles/adding-a-search-box-to-figure-toolbar#uifigure" target="_blank">presumably around 2018-2020</a>) that web-based (rather than Java-based) figures should become the default <i><b>figure</b></i> type. By keeping the underlying figure technology undocumented and retaining the documented top-level behavior (properties and methods of the figure handle), Matlab users who only use the documented interface should expect a relatively smooth transition at that time.<br />
So does this mean that users who start using AppDesigner today (and especially in a few years when web figures become the default) can no longer enjoy the benefits of figure-based customization offered to the existing Java-based figure users (which I listed in last month&#8217;s post)? Absolutely not! All we need is to get a hook into the <i><b>uifigure</b></i>&#8216;s underlying object and then we can start having fun.</p>
<h3 id="Controller">The <i>uifigure</i> Controller</h3>
<p>One way to do this is to use the <i><b>uifigure</b></i> handle&#8217;s hidden (private) <b>Controller</b> property (a <code>matlab.ui.internal.controller.FigureController</code> MCOS object whose source-code appears in <i>%matlabroot%/toolbox/matlab/uitools/uicomponents/components/+matlab/+ui/+internal/+controller/</i>).<br />
<b>Controller</b> is not only a hidden but also a private property of the figure handle, so we cannot simply use the <i><b>get</b></i> function to get its value. This doesn&#8217;t stop us of course: We can get the controller object using either my <a href="/articles/getundoc-get-undocumented-object-properties" target="_blank"><i><b>getundoc</b></i> utility</a> or the builtin <i><b>struct</b></i> function (which <a href="/articles/accessing-private-object-properties" target="_blank">returns private/protected properties</a> as an undocumented feature):</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;">&gt;&gt; hFig = uifigure<span style="color: #080;">(</span><span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'Yair'</span>, <span style="color: #F0F;">...</span><span style="color: #080;">)</span>;
&nbsp;
&gt;&gt; figProps = <span style="color: #0000FF;">struct</span><span style="color: #080;">(</span>hFig<span style="color: #080;">)</span>;  <span style="color: #228B22;">% or getundoc(hFig)</span>
<span style="color: #F5B666;">Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be
avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
(Type "<u>warning off MATLAB:structOnObject</u>" to suppress this warning.)</span>
&nbsp;
<span style="color: #F5B666;">Warning: figure JavaFrame property will be obsoleted in a future release. For more information see
<u>the JavaFrame resource on the MathWorks web site</u>.
(Type "<u>warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame</u>" to suppress this warning.)</span>
&nbsp;
figProps =
                      JavaFrame: <span style="color: #080;">[</span><span style="color: #080;">]</span>
                    JavaFrame_I: <span style="color: #080;">[</span><span style="color: #080;">]</span>
                       Position: <span style="color: #080;">[</span><span style="color: #33f;">87</span> <span style="color: #33f;">40</span> <span style="color: #33f;">584</span> <span style="color: #33f;">465</span><span style="color: #080;">]</span>
                   PositionMode: <span style="color:#A020F0;">'auto'</span>
                            <span style="color: #F0F;">...</span>
                     <span style="">Controller</span>: <span style="color: #080;">[</span>1x1 matlab.<span style="">ui</span>.<span style="">internal</span>.<span style="">controller</span>.<span style="">FigureController</span><span style="color: #080;">]</span>
                 ControllerMode: <span style="color:#A020F0;">'auto'</span>
                            <span style="color: #F0F;">...</span>
&nbsp;
&gt;&gt; figProps.<span style="">Controller</span>
ans =
  FigureController with <span style="color: #0000FF;">properties</span>:
&nbsp;
       Canvas: <span style="color: #080;">[</span><span style="color: #080;">]</span>
    ProxyView: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; figProps.<span style="">Controller</span>.<span style="">ProxyView</span>
ans =
            PeerNode: <span style="color: #080;">[</span>1x1 com.<span style="">mathworks</span>.<span style="">peermodel</span>.<span style="">impl</span>.<span style="">PeerNodeImpl</span><span style="color: #080;">]</span>
    PeerModelManager: <span style="color: #080;">[</span>1x1 com.<span style="">mathworks</span>.<span style="">peermodel</span>.<span style="">impl</span>.<span style="">PeerModelManagerImpl</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">struct</span><span style="color: #080;">(</span>figProps.<span style="">Controller</span><span style="color: #080;">)</span>
<span style="color: #F5B666;">Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be
avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
(Type "<u>warning off MATLAB:structOnObject</u>" to suppress this warning.)</span>
&nbsp;
ans =
               PositionListener: <span style="color: #080;">[</span>1x1 event.<span style="">listener</span><span style="color: #080;">]</span>
    ContainerPositionCorrection: <span style="color: #080;">[</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: #080;">]</span>
                      Container: <span style="color: #080;">[</span>1x1 matlab.<span style="">ui</span>.<span style="">internal</span>.<span style="">controller</span>.<span style="">FigureContainer</span><span style="color: #080;">]</span>
                         Canvas: <span style="color: #080;">[</span><span style="color: #080;">]</span>
                  IsClientReady: <span style="color: #33f;">1</span>
              PeerEventListener: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">]</span>
                      ProxyView: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">]</span>
                          Model: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">Figure</span><span style="color: #080;">]</span>
               ParentController: <span style="color: #080;">[</span>0x0 handle<span style="color: #080;">]</span>
      PropertyManagementService: <span style="color: #080;">[</span>1x1 matlab.<span style="">ui</span>.<span style="">internal</span>.<span style="">componentframework</span>.<span style="">services</span>.<span style="">core</span>.<span style="">propertymanagement</span>.<span style="">PropertyManagementService</span><span style="color: #080;">]</span>
          IdentificationService: <span style="color: #080;">[</span>1x1 matlab.<span style="">ui</span>.<span style="">internal</span>.<span style="">componentframework</span>.<span style="">services</span>.<span style="">core</span>.<span style="">identification</span>.<span style="">WebIdentificationService</span><span style="color: #080;">]</span>
           EventHandlingService: <span style="color: #080;">[</span>1x1 matlab.<span style="">ui</span>.<span style="">internal</span>.<span style="">componentframework</span>.<span style="">services</span>.<span style="">core</span>.<span style="">eventhandling</span>.<span style="">WebEventHandlingService</span><span style="color: #080;">]</span></pre>
</div>
</div>
<p>I will discuss all the goodies here in a future post (if you are curious then feel free to start drilling in there yourself, I promise it won&#8217;t bite you&#8230;). However, today I wish to concentrate on more immediate benefits from a different venue:</p>
<h3 id="webwindow">The <i>uifigure</i> webwindow</h3>
<p><i><b>uifigure</b></i>s are basically webpages rather than desktop windows (JFrames). They use an entirely different UI mechanism, based on HTML webpages served from a localhost webserver that runs CEF (<a href="https://en.wikipedia.org/wiki/Chromium_Embedded_Framework" rel="nofollow" target="_blank">Chromium Embedded Framework</a> version 3.2272 on <a href="https://www.chromium.org/developers/calendar" rel="nofollow" target="_blank">Chromium 41</a> in R2016a). This runs the so-called CEF client (apparently an adaptation of the CefClient sample application that comes with CEF; the relevant Matlab source-code is in <i>%matlabroot%/toolbox/matlab/cefclient/</i>). It uses the <a href="https://dojotoolkit.org" rel="nofollow" target="_blank">DOJO Javascript toolkit</a> for UI controls visualization and interaction, rather than Java Swing as in the existing JFrame figures. I still don&#8217;t know if there is a way to combine the seemingly disparate sets of GUIs (namely adding Java-based controls to web-based figures or vice-versa).<br />
Anyway, the important thing to note for my purposes today is that when a new <i><b>uifigure</b></i> is created, the above-mentioned Controller object is created, which in turn creates a new <code>matlab.internal.webwindow</code>. The webwindow class (<i>%matlabroot%/toolbox/matlab/cefclient/+matlab/+internal/webwindow.m</i>) is well-documented and easy to follow (although the non camel-cased class name escaped someone&#8217;s attention), and allows access to several important figure-level customizations.<br />
The figure&#8217;s <code>webwindow</code> reference can be accessed via the <b>Controller</b>&#8216;s <b>Container</b>&#8216;s <b>CEF</b> property:</p>
<pre lang="matlab">
>> hFig = uifigure('Name','Yair', ...);
>> warning off MATLAB:structOnObject      % suppress warning (yes, we know it's naughty...)
>> figProps = struct(hFig);
>> controller = figProps.Controller;      % Controller is a private hidden property of Figure
>> controllerProps = struct(controller);
>> container = controllerProps.Container  % Container is a private hidden property of FigureController
container =
  FigureContainer with properties:
    FigurePeerNode: [1x1 com.mathworks.peermodel.impl.PeerNodeImpl]
         Resizable: 1
          Position: [86 39 584 465]
               Tag: ''
             Title: 'Yair'
              Icon: 'C:\Program Files\Matlab\R2016a\toolbox\matlab\uitools\uicomponents\resources\images…'
           Visible: 1
               URL: 'http://localhost:31417/toolbox/matlab/uitools/uifigureappjs/componentContainer.html…'
              HTML: 'toolbox/matlab/uitools/uifigureappjs/componentContainer.html'
     ConnectorPort: 31417
         DebugPort: 0
     IsWindowValid: 1
>> win = container.CEF   % CEF is a regular (public) hidden property of FigureContainer
win =
  webwindow with properties:
                             URL: 'http://localhost:31417/toolbox/matlab/uitools/uifigureappjs/component…'
                           Title: 'Yair'
                            Icon: 'C:\Program Files\Matlab\R2016a\toolbox\matlab\uitools\uicomponents\re…'
                        Position: [86 39 584 465]
     CustomWindowClosingCallback: @(o,e)this.Model.hgclose()
    CustomWindowResizingCallback: @(event,data)resizeRequest(this,event,data)
                  WindowResizing: []
                   WindowResized: []
                     FocusGained: []
                       FocusLost: []
                DownloadCallback: []
        PageLoadFinishedCallback: []
           MATLABClosingCallback: []
      MATLABWindowExitedCallback: []
             PopUpWindowCallback: []
             RemoteDebuggingPort: 0
                      CEFVersion: '3.2272.2072'
                 ChromiumVersion: '41.0.2272.76'
                   isWindowValid: 1
               isDownloadingFile: 0
                         isModal: 0
                  isWindowActive: 1
                   isAlwaysOnTop: 0
                     isAllActive: 1
                     isResizable: 1
                         MaxSize: []
                         MinSize: []
>> win.URL
ans =
http://localhost:31417/toolbox/matlab/uitools/uifigureappjs/componentContainer.html?channel=/uicontainer/393ed66a-5e34-41f3-8ac0-0b0f3b0738cd&snc=5C2353
</pre>
<p>An alternative way to get the <code>webwindow</code> is via the list of all <code>webwindow</code>s stored by a central <code>webwindowmanager</code>:</p>
<pre lang="matlab">
webWindows = matlab.internal.webwindowmanager.instance.findAllWebwindows();  % manager method returning an array of all open webwindows
webWindows = matlab.internal.webwindowmanager.instance.windowList;           % equivalent alternative via manager's windowList property
</pre>
<p>Note that the controller, container and webwindow class objects, like most Matlab MCOS objects, have internal (hidden) properties/methods that you can explore. For example:</p>
<pre lang="matlab">
>> getundoc(win)
ans =
                   Channel: [1x1 asyncio.Channel]
       CustomEventListener: [1x1 event.listener]
           InitialPosition: [100 100 600 400]
    JavaScriptReturnStatus: []
     JavaScriptReturnValue: []
     NewWindowBeingCreated: 0
          NewWindowCreated: 1
           UpdatedPosition: [86 39 584 465]
              WindowHandle: 2559756
                    newURL: 'http://localhost:31417/toolbox/matlab/uitools/uifigureappjs/componentContai…'
</pre>
<h3 id="customizations">Using webwindow for figure-level customizations</h3>
<p>We can use the methods of this <code>webwindow</code> object as follows:</p>
<pre lang="matlab">
win.setAlwaysOnTop(true);   % always on top of other figure windows (a.k.a. AOT)
win.hide();
win.show();
win.bringToFront();
win.minimize();
win.maximize();
win.restore();
win.setMaxSize([400,600]);  % enables resizing up to this size but not larger (default=[])
win.setMinSize([200,300]);  % enables resizing down to this size but not smaller (default=[])
win.setResizable(false);
win.setWindowAsModal(true);
win.setActivateCurrentWindow(false);  % disable interaction with this entire window
win.setActivateAllWindows(false);     % disable interaction with *ALL* uifigure (but not Java-based) windows
result = win.executeJS(jsStr, timeout);  % run JavaScript
</pre>
<p>In addition to these methods, we can set callback functions to various callbacks exposed by the <code>webwindow</code> as regular properties (too bad that some of their names [like the class name itself] don&#8217;t follow Matlab&#8217;s standard naming convention, in this case by appending &#8220;Fcn&#8221; or &#8220;Callback&#8221;):</p>
<pre lang="matlab">
win.FocusGained = @someCallbackFunc;
win.FocusLost = @anotherCallbackFunc;
</pre>
<p>In summary, while the possible <a href="/articles/figure-window-customizations" target="_blank">customizations to Java-based figure windows</a> are more extensive, the <code>webwindow</code> methods appear to cover most of the important ones. Since these functionalities (maximize/minimize, AOT, disable etc.) are now common to both the Java and web-based figures, I really hope that MathWorks will create fully-documented <i><b>figure</b></i> properties/methods for them. Now that there is no longer any question whether these features will be supported by the future technology, and since there is no question as to their usefulness, there is really no reason not to officially support them in both figure types. If you feel the same as I do, please let MathWorks know about this &#8211; if enough people request this, MathWorks will be more likely to add these features to one of the upcoming Matlab releases.<br />
<b><u>Warning</u></b>: the internal implementation is subject to change across releases, so be careful to make your code cross-release compatible whenever you rely on one of Matlab&#8217;s internal objects.<br />
Note that I labeled this post as &#8220;part 1&#8221; &#8211; I expect to post additional articles on <i><b>uifigure</b></i> customizations in upcoming years. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1">Customizing uifigures part 1</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-print-setup" rel="bookmark" title="Customizing print setup">Customizing print setup </a> <small>Matlab figures print-setup can be customized to automatically prepare the figure for printing in a specific configuration...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-uifigures-part-1/feed</wfw:commentRss>
			<slash:comments>24</slash:comments>
		
		
			</item>
		<item>
		<title>Adding a search box to figure toolbar</title>
		<link>https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-a-search-box-to-figure-toolbar</link>
					<comments>https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Mar 2016 13:50:53 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Public presentation]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Internal component]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6353</guid>

					<description><![CDATA[<p>An interactive search-box can easily be added to a Matlab figure toolbar for enhanced user experience. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar">Adding a search box to figure toolbar</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-customizations" rel="bookmark" title="Figure toolbar customizations">Figure toolbar customizations </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar" rel="bookmark" title="Customizing the standard figure toolbar, menubar">Customizing the standard figure toolbar, menubar </a> <small>The standard figure toolbar and menubar can easily be modified to include a list of recently-used files....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I wrote about my <a href="/articles/upcoming-public-matlab-presentations" target="_blank">upcoming presentations</a> in Tel Aviv and Munich, where I will discuss a Matlab-based financial application that uses some advanced GUI concepts. In today&#8217;s post I will review one of these concepts that could be useful in a wide range of Matlab applications &#8211; adding an interactive search box to the toolbar of Matlab figures.<br />
The basic idea is simple: whenever the user types in the search box, a Matlab callback function checks the data for the search term. If one or more matches are found then the searchbox&#8217;s background remains white, otherwise it is colored yellow to highlight the term. When the user presses &lt;Enter&gt;, the search action is triggered to highlight the term in the data, and any subsequent press of &lt;Enter&gt; will highlight the next match (cycling back at the top as needed). Very simple and intuitive:<br />
<center><figure style="width: 600px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Interactive search-box in Matlab figure toolbar" src="https://undocumentedmatlab.com/images/Pairformax_search_animated.gif" title="Interactive search-box in Matlab figure toolbar" width="600" height="345" /><figcaption class="wp-caption-text">Interactive search-box in Matlab figure toolbar</figcaption></figure></center><br />
<span id="more-6353"></span><br />
In my specific case, the search action (highlighting the search term in the data) involved doing a lot of work: updating multiple charts and synchronizing row selection in several connected uitables. For this reason, I chose not to do this action interactively (upon each keypress in the search box) but rather only upon clicking &lt;Enter&gt;. In your implementation, if the search action is simpler and faster, you could do it interactively for an even more intuitive effect.</p>
<h3 id="components">Technical components</h3>
<p>The pieces of today&#8217;s post were already discussed separately on this website, but never shown together as I will do today:</p>
<ul>
<li>The search box component (<code>com.mathworks.widgets.SearchTextField</code>) was discussed in last year&#8217;s article on <a href="/articles/auto-completion-widget" target="_blank">auto-completion widgets</a></li>
<li>I showed how to <a href="/articles/figure-toolbar-components" target="_blank">add custom controls to the figure toolbar</a> in a 2009 post (time flies!)</li>
<li>I discussed <a href="/articles/figure-toolbar-customizations" target="_blank">controlling toolbar components&#8217; size</a> in another old post</li>
<li>I discussed my <a href="/articles/findjobj-find-underlying-java-object" target="_blank"><i><b>findjobj</b></i> utility</a>, used for accessing the underlying Java components of Matlab uicontrols in another article</li>
<li>I discussed <a href="/articles/matlab-and-the-event-dispatch-thread-edt" target="_blank">Matlab&#8217;s use of EDT</a> in a dedicated article on the subject back in 2010 (and I&#8217;ll have more to say about this subject next week)</li>
<li>Finally, I discussed how to trap Java control events in Matlab in separate articles <a href="/articles/uicontrol-callbacks" target="_blank">here</a> and <a href="/articles/matlab-callbacks-for-java-events-in-r2014a" target="_blank">here</a></li>
</ul>
<h3 id="toolbar">Adding a search-box to the figure toolbar</h3>
<p>As a first step, let&#8217;s create the search-box component and add it to our figure&#8217;s toolbar:</p>
<pre lang="matlab">
% First, create the search-box component on the EDT, complete with invokable Matlab callbacks:
jSearch = com.mathworks.widgets.SearchTextField('Symbol');  % 'Symbol' is my default search prompt
jSearchPanel = javaObjectEDT(jSearch.getComponent);  % this is a com.mathworks.mwswing.MJPanel object
jSearchPanel = handle(jSearchPanel, 'CallbackProperties');  % enable Matlab callbacks
% Now, set a fixed size for this component so that it does not resize when the figure resizes:
jSize = java.awt.Dimension(100,25);  % 100px wide, 25px tall
jSearchPanel.setMaximumSize(jSize)
jSearchPanel.setMinimumSize(jSize)
jSearchPanel.setPreferredSize(jSize)
jSearchPanel.setSize(jSize)
% Now, attach the Matlab callback function to search box events (key-clicks, Enter, and icon clicks):
jSearchBox = handle(javaObjectEDT(jSearchPanel.getComponent(0)), 'CallbackProperties');
set(jSearchBox, 'ActionPerformedCallback', {@searchSymbol,hFig,jSearchBox})
set(jSearchBox, 'KeyPressedCallback',      {@searchSymbol,hFig,jSearchBox})
jClearButton = handle(javaObjectEDT(jSearchPanel.getComponent(1)), 'CallbackProperties');
set(jClearButton, 'ActionPerformedCallback', {@searchSymbol,hFig,jSearchBox})
% Now, get the handle for the figure's toolbar:
hToolbar = findall(hFig,'tag','FigureToolBar');
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');  % or: hToolbar.JavaContainer.getComponentPeer
% Now, justify the search-box to the right of the toolbar using an invisible filler control
% (first add the filler control to the toolbar, then the search-box control):
jFiller = javax.swing.Box.createHorizontalGlue;  % this is a javax.swing.Box$Filler object
jToolbar.add(jFiller,      jToolbar.getComponentCount);
jToolbar.add(jSearchPanel, jToolbar.getComponentCount);
% Finally, refresh the toolbar so that the new control is displayed:
jToolbar.revalidate
jToolbar.repaint
</pre>
<h3 id="search">Search action callback functionality</h3>
<p>Now that the control is displayed in the toolbar, let&#8217;s define what our Matlab callback function <i>searchSymbol()</i> does. Remember that this callback function is invoked whenever any of the possible events occur: keypress, &lt;Enter&gt;, or clicking the search-box&#8217;s icon (typically the &#8220;x&#8221; icon, to clear the search term).<br />
We first reset the search-box appearance (foreground/background colors), then we check the search term (if non-empty). Based on the selected tab, we search the corresponding data table&#8217;s symbol column(s) for the search term. If no match is found, we highlight the search term by setting the search-box&#8217;s text to be red over yellow. Otherwise, we change the table&#8217;s selected row to the next match&#8217;s row index (i.e., the row following the table&#8217;s currently-selected row, cycling back at the top of the table if no match is found lower in the table).<br />
Reading and updating the table&#8217;s selected row requires using my <a href="/articles/findjobj-find-underlying-java-object" target="_blank"><i><b>findjobj</b></i> utility</a> &#8211; for performance considerations the jTable handle should be cached (perhaps in the hTable&#8217;s <b>UserData</b> or <b>ApplicationData</b>):</p>
<pre lang="matlab">
% Callback function to search for a symbol
function searchSymbol(hObject, eventData, hFig, jSearchBox)
    try
        % Clear search-box formatting
        jSearchBox.setBackground(java.awt.Color.white)
        jSearchBox.setForeground(java.awt.Color.black)
        jSearchBox.setSelectedTextColor(java.awt.Color.black)
        jSearchBox.repaint
        % Search for the specified symbol in the data table
        symbol = char(jSearchBox.getText);
        if ~isempty(symbol)
            handles = guidata(hFig);
            hTab = handles.hTabGroup.SelectedTab;
            colOffset = 0;
            forceCol0 = false;
            switch hTab.Title
                case 'Scanning'
                    hTable = handles.tbScanResults;
                    symbols = cell(hTable.Data(:,1));
                case 'Correlation'
                    hTable = handles.tbCorrResults;
                    symbols = cell(hTable.Data(:,1:2));
                case 'Backtesting'
                    hTab = handles.hBacktestTabGroup.SelectedTab;
                    hTable = findobj(hTab, 'Type','uitable', 'Tag','results');
                    pairs = cell(hTable.Data(:,1));
                    symbols = cellfun(@(c)strsplit(c,'/'), pairs, 'uniform',false);
                    symbols = reshape([symbols{:}],2,[])';
                    forceCol0 = true;
                case 'Trading'
                    hTable = handles.tbTrading;
                    symbols = cell(hTable.Data(:,2:3));
                    colOffset = 1;
                otherwise  % ignore
                    return
            end
            if isempty(symbols)
                return
            end
            [rows,cols] = ind2sub(size(symbols), find(strcmpi(symbol,symbols)));
            if isempty(rows)
                % Not found - highlight the search term
                jSearchBox.setBackground(java.awt.Color.yellow)
                jSearchBox.setForeground(java.awt.Color.red)
                jSearchBox.setSelectedTextColor(java.awt.Color.red)
                jSearchBox.repaint
            elseif isa(eventData, 'java.awt.event.KeyEvent') && isequal(eventData.getKeyCode,10)
                % Found with <enter> event - highlight the relevant data row
                jTable = findjobj(hTable);
                try jTable = jTable.getViewport.getView; catch, end  % in case findjobj returns the containing scrollpane rather than the jTable
                [rows, sortedIdx] = sort(rows);
                cols = cols(sortedIdx);
                currentRow = jTable.getSelectedRow + 1;
                idx = find(rows>currentRow,1);
                if isempty(idx),  idx = 1;  end
                if forceCol0
                    jTable.changeSelection(rows(idx)-1, 0, false, false)
                else
                    jTable.changeSelection(rows(idx)-1, cols(idx)-1+colOffset, false, false)
                end
                jTable.repaint
                jTable.getTableHeader.repaint
                jTable.getParent.getParent.repaint
                drawnow
            end
        end
    catch
        % never mind - ignore
    end
end
</pre>
<p>That&#8217;s all there is to it. In my specific case, changing the table&#8217;s selected row cased an immediate trigger that updated the associated charts, synchronized the other data tables and did several other background tasks.</p>
<h3 id="uifigure">What about the new web-based uifigure?</h3>
<p>The discussion above refers only to traditional Matlab <i><b>figure</b></i>s (both HG1 and HG2), not to the new web-based (AppDesigner) <i><b>uifigure</b></i>s that were officially introduced in R2016a (I <a href="/articles/sliders-in-matlab-gui#AppDesigner" target="_blank">wrote about it</a> last year).<br />
AppDesigner uifigures are basically webpages rather than desktop windows (JFrames). They use an entirely different UI mechanism, based on HTML webpages served from a localhost webserver, using the <a href="https://dojotoolkit.org" rel="nofollow" target="_blank">DOJO Javascript toolkit</a> for visualization and interaction, rather than Java Swing as in the existing JFrame figures. The existing figures still work without change, and are expected to continue working alongside the new uifigures for the foreseeable future. I&#8217;ll discuss the new uifigures in separate future posts (in the meantime you can read a bit about them in <a href="/articles/sliders-in-matlab-gui#AppDesigner" target="_blank">my post</a> from last year).<br />
I suspect that the new uifigures will replace the old figures at some point in the future, to enable a fully <a href="/articles/online-web-based-matlab" target="_blank">web-based (online) Matlab</a>. Will this happen in 2017 or 2027 ? &#8211; your guess is as good as mine, but my personal guesstimate is around 2018-2020.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar">Adding a search box to figure toolbar</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-components" rel="bookmark" title="Figure toolbar components">Figure toolbar components </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-toolbar-customizations" rel="bookmark" title="Figure toolbar customizations">Figure toolbar customizations </a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-standard-figure-toolbar-menubar" rel="bookmark" title="Customizing the standard figure toolbar, menubar">Customizing the standard figure toolbar, menubar </a> <small>The standard figure toolbar and menubar can easily be modified to include a list of recently-used files....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Sliders in Matlab GUI</title>
		<link>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sliders-in-matlab-gui</link>
					<comments>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 Jun 2015 18:00:58 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5827</guid>

					<description><![CDATA[<p>Professional-looking slider controls can easily be integrated in Matlab GUI. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui">Sliders in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui-part-2" rel="bookmark" title="Sliders in Matlab GUI &#8211; part 2">Sliders in Matlab GUI &#8211; part 2 </a> <small>Matlab contains a variety of ways to define/display slider controls in GUI windows. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>One of my consulting clients asked me last week if I knew an easy way to integrate a range (dual-knob) slider control in Matlab GUI. Today&#8217;s post is an expansion of the answer I provided him, which I though might interest other Matlab users.</p>
<ul>
<li><a href="/articles/sliders-in-matlab-gui#Matlab">Matlab vs. Java sliders</a></li>
<li><a href="/articles/sliders-in-matlab-gui#JSlider">Using JSlider</a></li>
<li><a href="/articles/sliders-in-matlab-gui#range">Range (dual-knob) sliders</a></li>
<li><a href="/articles/sliders-in-matlab-gui#AppDesigner">AppDesigner &#8211; Matlab&#8217;s new GUI</a></li>
<li><a href="/articles/sliders-in-matlab-gui#conclusions">Conclusions and some personal musings</a></li>
</ul>
<h3 id="Matlab">Matlab vs. Java sliders</h3>
<p>As funny as it may sound, Matlab&#8217;s so-called &#8220;slider&#8221; control (<code>uicontrol('Style','slider')</code>) is actually implemented as a scroll-bar, rather than the more natural <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html">JSlider</a>. I believe that this is due to a design decision that occurred sometime in the 1990&#8217;s (sliders were not as prevalent then as they are nowadays). This was never corrected, probably for backward-compatibility reasons. So to this day, Matlab&#8217;s so-called &#8220;slider&#8221; is actually a scroll-bar, and we do not [yet] have a real slider control in standard Matlab, apparently since the &#8216;slider&#8217; <i><b>uicontrol</b></i> style is already in use. Spoiler alert: this <i>will</i> change soon &#8212; keep reading.<br />
It gets worse: for some reason Matlab&#8217;s implementation of the so-called &#8220;slider&#8221; uses a Windows95 look-and-feel that makes the control look antique in today&#8217;s GUI standards. Using Java Swing&#8217;s standard <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JScrollBar.html">JScrollBar</a> control would at least have made it appear more consistent with the other Matlab controls, which are all based more closely on Java Swing:<br />
<figure style="width: 210px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt='Matlab "slider" uicontrol (bottom), Java JScrollBar (above), and JSlider (top 2)' src="https://undocumentedmatlab.com/images/slider_vs_scrollbars.gif" title='Matlab "slider" uicontrol (bottom), Java JScrollBar (above), and JSlider (top 2)' width="210" height="145" /><figcaption class="wp-caption-text">Matlab "slider" <i><b>uicontrol</b></i> (bottom), <br />Java <code>JScrollBar</code> (above), <br />and <code>JSlider</code> (top 2)</figcaption></figure></p>
<pre lang='matlab'>
% Standard Matlab "slider"
uicontrol('style','slider', 'position',[10,10,200,20]);
% Standard Java JScrollBar
jScrollbar = javax.swing.JScrollBar;
jScrollbar.setOrientation(jScrollbar.HORIZONTAL);
javacomponent(jScrollbar,[10,40,200,20]);
% Standard Java JSlider (20px high if no ticks/labels, otherwise use 45px)
jSlider = javax.swing.JSlider;
javacomponent(jSlider,[10,70,200,45]);
</pre>
<p>I advise users of the current Matlab GUI to use <code>JScrollBar</code> or <code>JSlider</code>, rather than Matlab&#8217;s standard &#8220;slider&#8221; <i><b>uicontrol</b></i>. The rest of today&#8217;s post will discuss the <code>JSlider</code> variant.<br />
<span id="more-5827"></span></p>
<h3 id="JSlider">Using JSlider</h3>
<p>As shown above, we can use the <i><b><a target="_blank" href="/articles/javacomponent">javacomponent</a></b></i> function to display any Java component in a Matlab container (such as <i><b>uipanel</b></i> or figure). We can easily modify the slider&#8217;s appearance using its internal properties:</p>
<pre lang='matlab'>set(jSlider, 'Value',84, 'MajorTickSpacing',20, 'PaintLabels',true);  % with labels, no ticks</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x016.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>set(jSlider, 'Value',22, 'PaintLabels',false, 'PaintTicks',true);  % with ticks, no labels</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x017.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>jSlider.setPaintLabels(true);  % or: jSlider.setPaintLabels(1);  % with both ticks and labels</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x018.png" title="JSlider customization" alt="JSlider customization" width="130" height="40" /></center></p>
<pre lang='matlab'>
[jhSlider, hContainer] = javacomponent(jSlider,[10,10,100,40]);
set(jSlider, 'Value',72, 'Orientation',jSlider.VERTICAL, 'MinorTickSpacing',5);
set(hContainer,'position',[10,10,40,100]); %note container size change
</pre>
<p><center><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/003x019.png" title="JSlider customization" alt="JSlider customization" width="70" height="120" /></center><br />
We can query the current slider value via its <b>Value</b> property:</p>
<pre lang='matlab'>
>> value = get(jSlider,'Value');  % or: value = jSlider.getValue;
value =
    29
</pre>
<p>We can easily attach Matlab callback functions to slider value-change events:</p>
<pre lang='matlab'>
>> hjSlider = handle(jSlider, 'CallbackProperties')
hjSlider =
	javahandle_withcallbacks.javax.swing.JSlider
>> hjSlider.StateChangedCallback = @(hjSlider,eventData) disp(get(hjSlider,'Value'));
>> set(hjSlider, 'StateChangedCallback', @myCallback);  %alternative
</pre>
<p>As you can see, standard Java controls (such as <code>JSlider</code> here) are very simple to customize and use in Matlab GUI. I have shown more complex customizations <a target="_blank" href="/articles/javacomponent#comment-80247">elsewhere in this blog</a>, as well as in my <a target="_blank" href="/books/matlab-java">Matlab-Java programming book</a>.<br />
Note that <code>JSlider</code> (and Java sliders in general) only supports integer values, so if you need floating-point values you&#8217;d either need to find some other Java Swing component somewhere that supports what you need, or do the scaling yourself with some text label. I recently created a Matlab class wrapper for a client that does exactly that: the underlying component was a  Java slider and the labels were updated to display floating-point values, dynamically updated based on the Matlab class object&#8217;s properties. It only took a short morning to create a fully-functional generic slider class that works quite well.</p>
<h3 id="range">Range (dual-knob) sliders</h3>
<p>This brings me to my client&#8217;s query that I mentioned at the beginning of this post: <code>JSlider</code> only contains a single knob. Is it possible to integrate a range (dual-knob) slider?<br />
My initial response was to simply google for &#8220;<a target="_blank" rel="nofollow" href="https://www.google.co.il/search?q=java%20range%20slider">Java range slider</a>&#8220;. This returns numerous different controls, both open-source and commercial, that we can download and integrate in Matlab. All it takes is to download the <i>*.class, *.zip</i> or <i>*.jar</i> file that contains the component, add it to Matlab Java classpath using the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/javaaddpath.html">javaaddpath</a></b></i> function, and then use the <i><b>javacomponent</b></i> to display it, just as we did with <code>JSlider</code> above.<br />
This is simple enough, but then I thought of an even simpler solution, namely to use JIDE&#8217;s library of commercial-grade controls that is pre-bundled in Matlab. Surely enough, a quick search in <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/overview-summary.html">JIDE&#8217;s enormous catalog</a> yielded its <code><a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/swing/RangeSlider.html">RangeSlider</a></code> component, which extends <code>JSlider</code> with a dual knob. <code>RangeSlider</code>&#8216;s appearance has changed somewhat across Matlab releases (or actually, JIDE releases, as they are integrated within the corresponding Matlab releases), but its basic functionality remained unchanged:</p>
<pre lang='matlab'>
jRangeSlider = com.jidesoft.swing.RangeSlider(0,100,20,70);  % min,max,low,high
jRangeSlider = javacomponent(jRangeSlider, [0,0,200,80], gcf);
set(jRangeSlider, 'MajorTickSpacing',25, 'MinorTickSpacing',5, 'PaintTicks',true, 'PaintLabels',true, ...
    'Background',java.awt.Color.white, 'StateChangedCallback',@myCallbackFunc);
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="RangeSlider in R2010b" src="https://undocumentedmatlab.com/images/RangeSlider_R2010b.gif" title="RangeSlider in R2010b" width="200" height="50" /> &nbsp; <img loading="lazy" decoding="async" alt="RangeSlider in R2014b" src="https://undocumentedmatlab.com/images/RangeSlider_R2014b.gif" title="RangeSlider in R2014b" width="200" height="50" /><figcaption class="wp-caption-text"><code>RangeSlider</code> in R2010b (left), R2014b (right)</figcaption></figure></center><br />
We can move the two knobs relative to each other. We can also move the entire range (i.e., both knobs at once), by either dragging the square on top of the right knob (R2010b), or by dragging the space between the two knobs (R2014b).<br />
The benefit of JIDE controls is that they are pre-bundled in every Matlab installation and deployed MCR. There is no need to download anything, nor to use <i><b>javaaddpath</b></i>. All the richness of JIDE&#8217;s commercial-grade libraries (at least those libraries used in Matlab, which is plenty) is automatically available to us within Matlab, just as easily as the standard Java Swing controls. MathWorks has already paid a small fortune to integrate JIDE&#8217;s libraries in Matlab, and we can use it free of charge within Matlab GUIs. This is a great (and sadly undocumented) advantage of Matlab GUI. Matlab GUI programmers who wish to enrich their GUI are strongly encourages to take the time to review the long list of controls provide by JIDE in Matlab. I&#8217;ve posted <a target="_blank" href="/articles/tag/jide">quite a few articles</a> on using JIDE components in Matlab &#8211; feel free to take a look and see the richness that JIDE can bring to your GUI. Additional material can be found in my Matlab-Java programming book.<br />
In the specific case of <code>RangeSlider</code>, this control is part of the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/oss.htm">JIDE Common Layer</a> that JideSoft open-sourced a few years ago. This means that we can <a target="_blank" rel="nofollow" href="https://github.com/jidesoft/jide-oss">download</a> the latest version of this library and use it in Matlab, in case it has some new component that is still not available in our version of Matlab. For example, Matlab R2014b includes JIDE version 3.4.1, released by JideSoft on May 2012 &#8211; the latest version (3.6.9, released last week) includes numerous fixes and improvements that were integrated in the past 3 years:</p>
<pre lang='matlab'>
>> com.jidesoft.utils.Lm.getProductVersion
ans =
3.4.1
</pre>
<p>Note that JIDE&#8217;s online documentation (<a target="_blank" rel="nofollow" href="https://www.jidesoft.com/products/JIDE_Common_Layer_Developer_Guide.pdf">PDF</a>, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/overview-summary.html">javadoc</a>, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/oss.htm">webpage</a>) always refers to the latest version. To use the latest Common-layer library in Matlab, simply <a target="_blank" rel="nofollow" href="https://github.com/jidesoft/jide-oss">download it</a> and replace Matlab&#8217;s pre-bundled <i>&lt;matlabroot&gt;/java/jarext/jide/jide-common.jar</i> file. Be careful with changing Matlab&#8217;s installation files (such as this one), as there is always a risk that some Matlab functionality might break. So always keep a copy of the original file, in case you need to revert your changes. Alternatively, place the <i>jide-common.jar</i> file in some other user folder and use it in Matlab on an as-needed basis using <i><b>javaaddpath</b></i> and <i><b>javarmpath</b></i>.<br />
Using the latest commercial (non-open-sourced) JIDE libraries, such as <i>jide-grids.jar</i>, <i>jide-components.jar</i> or <i>jide-charts.jar</i>, is only possible if you purchase them from JideSoft. But as noted, we can freely use the older bundled libraries in our Matlab GUIs without paying JideSoft anything.<br />
<b><u>Disclaimer</u></b>: I am an engineer, not a lawyer. What I said above is my personal opinion; it is not legal advice. If you are unsure about licensing of JIDE components in your programs, contact MathWorks or JideSoft.</p>
<h3 id="AppDesigner">AppDesigner &#8211; Matlab&#8217;s new GUI</h3>
<p>Last autumn, with little fanfare, MathWorks released the App Designer toolbox, which can be freely <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/48142-app-designer">downloaded from the File Exchange</a>. This is not just another File Exchange utility. It is in fact an official MathWorks <a target="_blank" rel="nofollow" href="http://www.mathworks.com/products/matlab/app-designer/tech-preview.html">Technical Preview</a> that is both functional by itself, and also provides very interesting insight of Matlab&#8217;s upcoming new GUI. MathWorks have not announced exactly when this new AppDesigner will replace the aging GUIDE in Matlab. But the fact that AppDesigner is an actual working product in the public domain since late 2014, and that MathWorks has officially endorsed it as a &#8220;Technical Preview&#8221;, mean that this day is close.<br />
In the new AppDesigner, sliders finally appear modern, complete with all sorts of customizable properties:<br />
<center><figure style="width: 598px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Sliders in Matlab's new AppDesigner" src="https://undocumentedmatlab.com/images/slider_AppDesigner.png" title="Sliders in Matlab's new AppDesigner" width="598" height="376" /><figcaption class="wp-caption-text">Sliders in Matlab's new AppDesigner</figcaption></figure></center><br />
Java controls still provide more customizability than Matlab, even in the new AppDesigner, but the functionality gap is now significantly reduced. This provides the flexibility of modern easy-to-create/maintain GUIs for users who do not need to preserve backward-compatibility with existing GUIs or extra customizabilty enabled by Java, while preserving the functionality for those who do.<br />
Java components and even standard Matlab <i><b>uicontrol</b></i>s cannot be added to an AppDesigner window because it is not a standard Java <code>JFrame</code> window. The new App window has its own set of controls, separate from <i><b>uicontrols</b></i> (topic for a separate blog post someday). However, we can always keep using <i><b>javacomponent</b></i> and <i><b>uicontrol</b></i> in plain-ol&#8217; figures, as before, side-by-side with the new AppDesigned windows. The new App window can be created using the new <i><b>appwindow</b></i> function, whereas the existing <i><b>figure</b></i> function creates a standard figure window (basically a Java <code>JFrame</code>) that accepts <i><b>javacomponent</b></i> and <i><b>uicontrol</b></i>. Maybe one day I&#8217;ll find out if there&#8217;s a way to combine these two seemingly disparate sets of GUIs. In the meantime I&#8217;m content that there&#8217;s a new way to create Matlab GUIs that has not previously existed.<br />
AppDesigner is a very nice addition for Matlab GUI builders, and it will get even better with time. Having looked at some of the internals, I&#8217;m drooling over the potential improvements. MathWorks has invested quite a bit in this new product, so I&#8217;m confident that many of these improvements will find their way into AppDesigner in the upcoming releases. I just hope it will remain a free utility and will not turn into an addon toolbox when officially released (I have not seen any mention about this either way, so it&#8217;s still an open question; I&#8217;ll clarify this point here when I learn something). For the time being, AppDesigner is free to use.<br />
MathWorks is actively looking for ways to improve AppDesigner, so if you find any functionality that is missing or buggy, please provide feedback:<br />
<center><figure style="width: 280px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Feedback for Matlab's new AppDesigner" src="http://www.mathworks.com/images/nextgen/supporting/products/matlab-app-designer/feedback.png" title="Feedback for Matlab's new AppDesigner" width="280" height="143" /><figcaption class="wp-caption-text">Feedback for Matlab's new AppDesigner</figcaption></figure></center></p>
<h3 id="conclusions">Conclusions and some personal musings</h3>
<p>Matlab itself has kept its Desktop GUI relatively modern, and integrates advanced JIDE GUI controls internally. But until AppDesigner came about, Matlab application builders were not provided with similarly modern documented GUI components and design tools, in keeping with the times.<br />
It is indeed possible, as I&#8217;ve <a target="_blank" href="/articles/auto-completion-widget">repeatedly claimed</a> in this blog, to create professional-looking GUIs in Matlab. However, this currently requires using undocumented features and Java controls.<br />
In Matlab&#8217;s upcoming AppDesigner, making professional-looking Matlab GUIs will be easier, with sleek new controls, user-friendly visual layout, and easy-to-maintain class-based code. I still find the tech-preview to be lacking in some respects, and not integrated with the existing GUI functionality. Still, the fact that MathWorks has gone out of its way to provide a Technical Preview of its upcoming new GUI, despite its normal reluctance to provide a technical development roadmap, shows a commitment to improving Matlab&#8217;s user-facing front-end. This makes me optimistic that most shortcomings will be solved by the time AppDesigner is officially released, hopefully soon.<br />
Until this happens, and possibly even later, we can significantly improve Matlab&#8217;s standard GUI using Java in standard figure windows. Interested readers can find out more information about integrating Java controls in Matlab GUI in my book &#8220;<i><b><a target="_blank" href="/books/matlab-java">Undocumented Secrets of MATLAB-Java Programming</a></b></i>&#8221; (CRC Press, 2011, ISBN 978-1439869031). If you already have this book, please be kind enough to post your feedback on it on Amazon (<a target="_blank" rel="nofollow" href="http://www.amazon.com/Undocumented-Secrets-MATLAB-Java-Programming-Altman/product-reviews/1439869030?sortBy=bySubmissionDateDescending#productSummary">link</a>), for the benefit of others.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui">Sliders in Matlab GUI</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sliders-in-matlab-gui-part-2" rel="bookmark" title="Sliders in Matlab GUI &#8211; part 2">Sliders in Matlab GUI &#8211; part 2 </a> <small>Matlab contains a variety of ways to define/display slider controls in GUI windows. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui" rel="bookmark" title="Using spinners in Matlab GUI">Using spinners in Matlab GUI </a> <small>Spinner controls can easily be added to Matlab GUI. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/date-selection-components" rel="bookmark" title="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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/sliders-in-matlab-gui/feed</wfw:commentRss>
			<slash:comments>59</slash:comments>
		
		
			</item>
	</channel>
</rss>
