<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>
	Comments on: Using spinners in Matlab GUI	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-spinners-in-matlab-gui</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sun, 18 Jul 2021 08:28:41 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-511246</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 18 Jul 2021 08:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-511246</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-511245&quot;&gt;Santiago&lt;/a&gt;.

yes - assuming you created the spinner using the &lt;code&gt;javacomponent&lt;/code&gt; function, you can modify the &lt;b&gt;Position&lt;/b&gt; and &lt;b&gt;Units&lt;/b&gt; properties of the component&#039;s container handle, which is the second output argument returned by &lt;code&gt;javacomponent&lt;/code&gt;. See http://undocumentedmatlab.com/articles/javacomponent for details.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-511245">Santiago</a>.</p>
<p>yes &#8211; assuming you created the spinner using the <code>javacomponent</code> function, you can modify the <b>Position</b> and <b>Units</b> properties of the component&#8217;s container handle, which is the second output argument returned by <code>javacomponent</code>. See <a href="http://undocumentedmatlab.com/articles/javacomponent" rel="ugc">http://undocumentedmatlab.com/articles/javacomponent</a> for details.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Santiago		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-511245</link>

		<dc:creator><![CDATA[Santiago]]></dc:creator>
		<pubDate>Sun, 18 Jul 2021 02:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-511245</guid>

					<description><![CDATA[Hi Yair.

Is it possible to modify the spinner&#039;s position (x, y, w, h)  after it has been created? I&#039;m trying to do it during a SizeChangedFcn callback.

Thanks.]]></description>
			<content:encoded><![CDATA[<p>Hi Yair.</p>
<p>Is it possible to modify the spinner&#8217;s position (x, y, w, h)  after it has been created? I&#8217;m trying to do it during a SizeChangedFcn callback.</p>
<p>Thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-420017</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 08 Mar 2018 23:22:43 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-420017</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-419234&quot;&gt;Asimov&lt;/a&gt;.

@Asimov - Java events often fire twice: first when the event processing starts, and then when the even processing ends. You can process only one of them by adding code in your callback function to prevent re-entrancy. For example:
&lt;pre lang=&quot;matlab&quot;&gt;
% Variant1
function myCallbackFcn1(hObject,eventData,varargin)
   persistent inCallback
   if ~isempty(inCallback),  return;  end
   inCallback = true;
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other GUI events a chance to bail out above
   inCallback = [];
end  % myCallbackFcn1
&lt;/pre&gt;

Additional information: &lt;a href=&quot;http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy&lt;/a&gt;

If you found my book useful, then please post a favorable review of it on Amazon - thanks in advance!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-419234">Asimov</a>.</p>
<p>@Asimov &#8211; Java events often fire twice: first when the event processing starts, and then when the even processing ends. You can process only one of them by adding code in your callback function to prevent re-entrancy. For example:</p>
<pre lang="matlab">
% Variant1
function myCallbackFcn1(hObject,eventData,varargin)
   persistent inCallback
   if ~isempty(inCallback),  return;  end
   inCallback = true;
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other GUI events a chance to bail out above
   inCallback = [];
end  % myCallbackFcn1
</pre>
<p>Additional information: <a href="http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy" target="_blank" rel="nofollow">http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy</a></p>
<p>If you found my book useful, then please post a favorable review of it on Amazon &#8211; thanks in advance!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Asimov		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-419234</link>

		<dc:creator><![CDATA[Asimov]]></dc:creator>
		<pubDate>Tue, 20 Feb 2018 03:29:19 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-419234</guid>

					<description><![CDATA[Hi, Yair!

I tried to add a &lt;b&gt;StateChangedCallback&lt;/b&gt; to the JSpinner, and if the value is modified, it will display the current value on the command line.

&lt;pre lang=&quot;matlab&quot;&gt;
import javax.swing.*
import java.awt.*
f = figure;

sm = SpinnerNumberModel(1.1, 0, 9, 0.3); % default, min, max, step
js = JSpinner(sm);
[jspinner, mspinner] = javacomponent(js);
set(jspinner,&#039;StateChangedCallback&#039;, &#039;disp(jspinner.getValue)&#039;);
&lt;/pre&gt;

However, I find a strange phenomenon, the callback is sometimes invoked twice.

The codes above will output someting like this:
&lt;pre lang=&quot;matlab&quot;&gt;
    1.4000 (click up)
    1.1000 (click down)
    1.1000
    0.8000 (click down)
    0.8000
    0.5000 (click down)
&lt;/pre&gt;

Notice that although I only click once, the &lt;b&gt;disp&lt;/b&gt; sometimes output two same results.

So I try to check whether the value is changed at the first time. However, something stranger happens.

I replace the &lt;b&gt;StateChangedCallback&lt;/b&gt; by the line below.

&lt;pre lang=&quot;matlab&quot;&gt;
set(jspinner,&#039;StateChangedCallback&#039;, &#039;disp([jspinner.getPreviousValue jspinner.getValue])&#039;);
&lt;/pre&gt;

Which outputs:
&lt;pre lang=&quot;matlab&quot;&gt;
    1.4000    1.7000 (click up)
    1.1000    1.4000 (click down)
    1.4000    1.7000 (click up)
    1.4000    1.7000
&lt;/pre&gt;

Notice that even the value is changed at line 3, it still &lt;b&gt;disp&lt;/b&gt; twice. 

And the &lt;b&gt;jspinner.getPreviousValue&lt;/b&gt; seems to not remember the result of the first time.

So I use a temperate value to check whether the value is the same with the previous. (Why I use a tmp value? Because the &lt;b&gt;jspinner.getPreviousValue&lt;/b&gt; failed in the case above.)

&lt;pre lang=&quot;matlab&quot;&gt;
tmp = 0;
set(jspinner,&#039;StateChangedCallback&#039;, ...
    &#039;if tmp~=jspinner.getValue;disp(tmp);tmp = jspinner.getValue; end&#039;);
&lt;/pre&gt;

This time, the output works fine, and it never outputs two same lines.

I guess the problem may be something related to the thread of java/matlab events, but I do not hava enough knowledge about it. The problem could be solved by adding a temp value and add an if-end sentence, but it would be better to know the reason.

Could you please help me find the reason of this problem?

By the way, your MATLAB-Java book and many blogs has helped me a lot! 

Thank you so much!]]></description>
			<content:encoded><![CDATA[<p>Hi, Yair!</p>
<p>I tried to add a <b>StateChangedCallback</b> to the JSpinner, and if the value is modified, it will display the current value on the command line.</p>
<pre lang="matlab">
import javax.swing.*
import java.awt.*
f = figure;

sm = SpinnerNumberModel(1.1, 0, 9, 0.3); % default, min, max, step
js = JSpinner(sm);
[jspinner, mspinner] = javacomponent(js);
set(jspinner,'StateChangedCallback', 'disp(jspinner.getValue)');
</pre>
<p>However, I find a strange phenomenon, the callback is sometimes invoked twice.</p>
<p>The codes above will output someting like this:</p>
<pre lang="matlab">
    1.4000 (click up)
    1.1000 (click down)
    1.1000
    0.8000 (click down)
    0.8000
    0.5000 (click down)
</pre>
<p>Notice that although I only click once, the <b>disp</b> sometimes output two same results.</p>
<p>So I try to check whether the value is changed at the first time. However, something stranger happens.</p>
<p>I replace the <b>StateChangedCallback</b> by the line below.</p>
<pre lang="matlab">
set(jspinner,'StateChangedCallback', 'disp([jspinner.getPreviousValue jspinner.getValue])');
</pre>
<p>Which outputs:</p>
<pre lang="matlab">
    1.4000    1.7000 (click up)
    1.1000    1.4000 (click down)
    1.4000    1.7000 (click up)
    1.4000    1.7000
</pre>
<p>Notice that even the value is changed at line 3, it still <b>disp</b> twice. </p>
<p>And the <b>jspinner.getPreviousValue</b> seems to not remember the result of the first time.</p>
<p>So I use a temperate value to check whether the value is the same with the previous. (Why I use a tmp value? Because the <b>jspinner.getPreviousValue</b> failed in the case above.)</p>
<pre lang="matlab">
tmp = 0;
set(jspinner,'StateChangedCallback', ...
    'if tmp~=jspinner.getValue;disp(tmp);tmp = jspinner.getValue; end');
</pre>
<p>This time, the output works fine, and it never outputs two same lines.</p>
<p>I guess the problem may be something related to the thread of java/matlab events, but I do not hava enough knowledge about it. The problem could be solved by adding a temp value and add an if-end sentence, but it would be better to know the reason.</p>
<p>Could you please help me find the reason of this problem?</p>
<p>By the way, your MATLAB-Java book and many blogs has helped me a lot! </p>
<p>Thank you so much!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alain Barraud		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368029</link>

		<dc:creator><![CDATA[Alain Barraud]]></dc:creator>
		<pubDate>Thu, 21 Jan 2016 18:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-368029</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368011&quot;&gt;Yair Altman&lt;/a&gt;.

@yair
I have found the reason. By default the decimal format is local dependent!!
In France it is , and not . 
Ok I&#039;ll look at your demo. 
However a last point as in your demo, if the user enters a value outside min or max (for example 2030 as year) the spinner is out of use.
Is there a special callback property to use in order to check this case.

Alain]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368011">Yair Altman</a>.</p>
<p>@yair<br />
I have found the reason. By default the decimal format is local dependent!!<br />
In France it is , and not .<br />
Ok I&#8217;ll look at your demo.<br />
However a last point as in your demo, if the user enters a value outside min or max (for example 2030 as year) the spinner is out of use.<br />
Is there a special callback property to use in order to check this case.</p>
<p>Alain</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368011</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 21 Jan 2016 09:46:46 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-368011</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368010&quot;&gt;Alain Barraud&lt;/a&gt;.

@Alain - see my &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/26970-spinnerdemo&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;i&gt;&lt;b&gt;SpinnerDemo&lt;/b&gt;&lt;/i&gt;&lt;/a&gt; (or read &lt;a href=&quot;http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;JSpinner&lt;/code&gt;&#039;s documentation&lt;/a&gt;) to see how to modify the text formatting.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368010">Alain Barraud</a>.</p>
<p>@Alain &#8211; see my <a href="http://www.mathworks.com/matlabcentral/fileexchange/26970-spinnerdemo" target="_blank" rel="nofollow"><i><b>SpinnerDemo</b></i></a> (or read <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html" target="_blank" rel="nofollow"><code>JSpinner</code>&#8216;s documentation</a>) to see how to modify the text formatting.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alain Barraud		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-368010</link>

		<dc:creator><![CDATA[Alain Barraud]]></dc:creator>
		<pubDate>Thu, 21 Jan 2016 09:30:02 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-368010</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367963&quot;&gt;Yair Altman&lt;/a&gt;.

@yair
Thanks a lot. It works fine. I had a similar problem with Spinner BackgroundColor and ForegroudColor. Now using for exemple
&lt;pre lang=&quot;matlab&quot;&gt;
val = num2cell([0 0.8 0.8]);
jhSpinner.getEditor.getTextField.setBackground(java.awt.Color(val{:}));
&lt;/pre&gt;
gives the expected result.

Why a non standard  &quot;Text: &#039;125,5&#039;&quot; property although the Value property is 
&quot;Value: 1.2550e+02&quot; ?
&lt;pre lang=&quot;matlab&quot;&gt;
jhSpinner.getEditor.getTextField.getFormatter
ans =
javax.swing.JSpinner$NumberEditorFormatter@a798948
&lt;/pre&gt;
Is there a way to modify something here?
Cheers
Alain]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367963">Yair Altman</a>.</p>
<p>@yair<br />
Thanks a lot. It works fine. I had a similar problem with Spinner BackgroundColor and ForegroudColor. Now using for exemple</p>
<pre lang="matlab">
val = num2cell([0 0.8 0.8]);
jhSpinner.getEditor.getTextField.setBackground(java.awt.Color(val{:}));
</pre>
<p>gives the expected result.</p>
<p>Why a non standard  &#8220;Text: &#8216;125,5&#8217;&#8221; property although the Value property is<br />
&#8220;Value: 1.2550e+02&#8221; ?</p>
<pre lang="matlab">
jhSpinner.getEditor.getTextField.getFormatter
ans =
javax.swing.JSpinner$NumberEditorFormatter@a798948
</pre>
<p>Is there a way to modify something here?<br />
Cheers<br />
Alain</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367963</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 20 Jan 2016 21:07:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-367963</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367957&quot;&gt;Alain Barraud&lt;/a&gt;.

@Alain - apparently the &lt;code&gt;JSpinner&lt;/code&gt; component creates its internal text-field using the parent control&#039;s &lt;b&gt;Font&lt;/b&gt; property value when it is first rendered, and then ignores changes to that parent property value. Instead, you can modify the text-field&#039;s &lt;b&gt;Font&lt;/b&gt; property (and its other property values) directly:

&lt;pre lang=&quot;matlab&quot;&gt;jhSpinner.getEditor.getTextField.setFont(java.awt.Font(&#039;Serif&#039;, 0, 20));&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367957">Alain Barraud</a>.</p>
<p>@Alain &#8211; apparently the <code>JSpinner</code> component creates its internal text-field using the parent control&#8217;s <b>Font</b> property value when it is first rendered, and then ignores changes to that parent property value. Instead, you can modify the text-field&#8217;s <b>Font</b> property (and its other property values) directly:</p>
<pre lang="matlab">jhSpinner.getEditor.getTextField.setFont(java.awt.Font('Serif', 0, 20));</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Alain Barraud		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-367957</link>

		<dc:creator><![CDATA[Alain Barraud]]></dc:creator>
		<pubDate>Wed, 20 Jan 2016 20:20:01 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-367957</guid>

					<description><![CDATA[hello yair,

consider the following spinner
&lt;pre lang=&quot;matlab&quot;&gt;
Model = javax.swing.SpinnerNumberModel(125,15,225,.5);
jSpinner = javax.swing.JSpinner(Model);
[jhSpinner,hghandle] = javacomponent(jSpinner)
jhSpinner.Font=java.awt.Font(&#039;Serif&#039;, 3, 50);
&lt;/pre&gt;
At this step all is right!

Now if I want to come back to non bold non italic
&lt;pre lang=&quot;matlab&quot;&gt;jhSpinner.Font=java.awt.Font(&#039;Serif&#039;, 0, 50);&lt;/pre&gt;
is without any effect!!?? Any idea?

Another curious point values appear as 140 140,5 141 ... and not 140.5 ??

Thanks
Alain]]></description>
			<content:encoded><![CDATA[<p>hello yair,</p>
<p>consider the following spinner</p>
<pre lang="matlab">
Model = javax.swing.SpinnerNumberModel(125,15,225,.5);
jSpinner = javax.swing.JSpinner(Model);
[jhSpinner,hghandle] = javacomponent(jSpinner)
jhSpinner.Font=java.awt.Font('Serif', 3, 50);
</pre>
<p>At this step all is right!</p>
<p>Now if I want to come back to non bold non italic</p>
<pre lang="matlab">jhSpinner.Font=java.awt.Font('Serif', 0, 50);</pre>
<p>is without any effect!!?? Any idea?</p>
<p>Another curious point values appear as 140 140,5 141 &#8230; and not 140.5 ??</p>
<p>Thanks<br />
Alain</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Xiangrui Li		</title>
		<link>https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-364116</link>

		<dc:creator><![CDATA[Xiangrui Li]]></dc:creator>
		<pubDate>Thu, 17 Dec 2015 03:23:59 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2679#comment-364116</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-364107&quot;&gt;Yair Altman&lt;/a&gt;.

Oh, yes. Thank you for the simple solution, Yair!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-spinners-in-matlab-gui#comment-364107">Yair Altman</a>.</p>
<p>Oh, yes. Thank you for the simple solution, Yair!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
