<?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: Customizing listbox &amp; editbox scrollbars</title>
	<atom:link href="http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/feed/" rel="self" type="application/rss+xml" />
	<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/</link>
	<description>Charting Matlab's unsupported hidden underbelly</description>
	<lastBuildDate>Tue, 07 Sep 2010 22:25:59 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Yair Altman</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-11239</link>
		<dc:creator>Yair Altman</dc:creator>
		<pubDate>Fri, 18 Jun 2010 15:08:52 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-11239</guid>
		<description>@Carrie, @Camilo and others: If you get an error when you try to use the enumerated (non-numeric) policy values, then you can simply cast the Matlab handle() of the Java reference back into a Java reference. For example:

&lt;pre lang=&quot;matlab&quot;&gt;jScrollPane.java.HORIZONTAL_SCROLLBAR_AS_NEEDED&lt;/pre&gt;

Alternately, as mentioned above, you can always use the numeric values of these enumerated policies. They are less readable/maintainable, but they always work :-)</description>
		<content:encoded><![CDATA[<p>@Carrie, @Camilo and others: If you get an error when you try to use the enumerated (non-numeric) policy values, then you can simply cast the Matlab handle() of the Java reference back into a Java reference. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jScrollPane.<span style="">java</span>.<span style="">HORIZONTAL_SCROLLBAR_AS_NEEDED</span></pre></div></div>

<p>Alternately, as mentioned above, you can always use the numeric values of these enumerated policies. They are less readable/maintainable, but they always work <img src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yair Altman</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-9909</link>
		<dc:creator>Yair Altman</dc:creator>
		<pubDate>Wed, 12 May 2010 14:51:09 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-9909</guid>
		<description>@Jeroen - It doesn&#039;t work in your creation callbacks because the figure is not yet visible at that point and &lt;i&gt;&lt;b&gt;findjobj&lt;/b&gt;&lt;/i&gt; requires a visible figure to find the underlying Java handles. This is why you see an empty handle list. This is also the reason it doesn&#039;t work in your _OpeningFcn() function. Instead, place your code in the _OutputFcn() function, which is called immediately after the figure becomes visible.</description>
		<content:encoded><![CDATA[<p>@Jeroen &#8211; It doesn&#8217;t work in your creation callbacks because the figure is not yet visible at that point and <i><b>findjobj</b></i> requires a visible figure to find the underlying Java handles. This is why you see an empty handle list. This is also the reason it doesn&#8217;t work in your _OpeningFcn() function. Instead, place your code in the _OutputFcn() function, which is called immediately after the figure becomes visible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeroen Boschma</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-9906</link>
		<dc:creator>Jeroen Boschma</dc:creator>
		<pubDate>Wed, 12 May 2010 13:27:03 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-9906</guid>
		<description>Hi Yair,

It works only half for me, hopefully you can point me in the correct direction. Currently working with :

-----------------------------------------------------------------------------------
MATLAB Version 7.4.0.287 (R2007a)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.5.0_07 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
-----------------------------------------------------------------------------------

For testing I put a button and edit on a figure in GUIDE, I have a function to change the properties of the edit:

&lt;pre lang=&quot;matlab&quot;&gt;
function r = set_edit_props(varargin)

r = true;
try
    h           = findobj(&#039;Tag&#039;, &#039;edit2&#039;);
    jScrollPane = findjobj(h);
    jViewPort   = jScrollPane.getViewport;
    jEditbox    = jViewPort.getComponent(0);
    %set(jScrollPane,&#039;HorizontalScrollBarPolicy&#039;, jScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    %set(jScrollPane,&#039;VerticalScrollBarPolicy&#039;, jScrollPane.VERTICAL_SCROLLBAR_NEVER);
    set(jScrollPane,&#039;HorizontalScrollBarPolicy&#039;, 32);
    set(jScrollPane,&#039;VerticalScrollBarPolicy&#039;, 21);
    jEditbox.setWrapping(false);
catch
    disp(lasterr)
    r = false;
end
&lt;/pre&gt;

I used the integer-values for the scrollbars because the named constants are not part of the Java object.

Problem: when I call the above function from the button-callback, then it works. But this is not what I want, I want that when the figure is made visible, the scrollbars are automatically OK. So what I tried:

1) call &#039;set_edit_props&#039; from edit create-callback:

jScrollPane =
 
    handle: 0-by-0
 
No appropriate method or public field getViewport for class handle.handle.

2) call &#039;set_edit_props&#039; after a 2 secs delay (timer-object) started within edit create-callback (try to let everything become visible before access is requested):

jScrollPane =
 
    handle: 1-by-0
 
No appropriate method or public field getViewport for class handle.handle.

3) call &#039;set_edit_props&#039; from OpeningFcn: result as with 2)

4) call &#039;set_edit_props&#039; via timer from OpeningFcn: result as with 1) (!)

Nothing works. Maybe you have some ideas....

Regards,

   Jeroen</description>
		<content:encoded><![CDATA[<p>Hi Yair,</p>
<p>It works only half for me, hopefully you can point me in the correct direction. Currently working with :</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
MATLAB Version 7.4.0.287 (R2007a)<br />
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)<br />
Java VM Version: Java 1.5.0_07 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>For testing I put a button and edit on a figure in GUIDE, I have a function to change the properties of the edit:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> r = set_edit_props<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
&nbsp;
r = <span style="color: #0000FF;">true</span>;
<span style="color: #0000FF;">try</span>
    h           = <span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>, <span style="color:#A020F0;">'edit2'</span><span style="color: #080;">&#41;</span>;
    jScrollPane = findjobj<span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span>;
    jViewPort   = jScrollPane.<span style="">getViewport</span>;
    jEditbox    = jViewPort.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
    <span style="color: #228B22;">%set(jScrollPane,'HorizontalScrollBarPolicy', jScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);</span>
    <span style="color: #228B22;">%set(jScrollPane,'VerticalScrollBarPolicy', jScrollPane.VERTICAL_SCROLLBAR_NEVER);</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jScrollPane,<span style="color:#A020F0;">'HorizontalScrollBarPolicy'</span>, <span style="color: #33f;">32</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jScrollPane,<span style="color:#A020F0;">'VerticalScrollBarPolicy'</span>, <span style="color: #33f;">21</span><span style="color: #080;">&#41;</span>;
    jEditbox.<span style="">setWrapping</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
    <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">lasterr</span><span style="color: #080;">&#41;</span>
    r = <span style="color: #0000FF;">false</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>I used the integer-values for the scrollbars because the named constants are not part of the Java object.</p>
<p>Problem: when I call the above function from the button-callback, then it works. But this is not what I want, I want that when the figure is made visible, the scrollbars are automatically OK. So what I tried:</p>
<p>1) call &#8217;set_edit_props&#8217; from edit create-callback:</p>
<p>jScrollPane =</p>
<p>    handle: 0-by-0</p>
<p>No appropriate method or public field getViewport for class handle.handle.</p>
<p>2) call &#8217;set_edit_props&#8217; after a 2 secs delay (timer-object) started within edit create-callback (try to let everything become visible before access is requested):</p>
<p>jScrollPane =</p>
<p>    handle: 1-by-0</p>
<p>No appropriate method or public field getViewport for class handle.handle.</p>
<p>3) call &#8217;set_edit_props&#8217; from OpeningFcn: result as with 2)</p>
<p>4) call &#8217;set_edit_props&#8217; via timer from OpeningFcn: result as with 1) (!)</p>
<p>Nothing works. Maybe you have some ideas&#8230;.</p>
<p>Regards,</p>
<p>   Jeroen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yair Altman</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-9326</link>
		<dc:creator>Yair Altman</dc:creator>
		<pubDate>Sat, 24 Apr 2010 18:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-9326</guid>
		<description>@Camilo - it would help to know which Matlab version, Java version and OS you have - in short, the output of the &lt;b&gt;&lt;i&gt;ver&lt;/i&gt;&lt;/b&gt; function in your Matlab command prompt. 

In the meantime, you can try Carrie&#039;s solution above - simply use the number 30 instead of jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED</description>
		<content:encoded><![CDATA[<p>@Camilo &#8211; it would help to know which Matlab version, Java version and OS you have &#8211; in short, the output of the <b><i>ver</i></b> function in your Matlab command prompt. </p>
<p>In the meantime, you can try Carrie&#8217;s solution above &#8211; simply use the number 30 instead of jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: camilo</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-9281</link>
		<dc:creator>camilo</dc:creator>
		<pubDate>Fri, 23 Apr 2010 15:21:48 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-9281</guid>
		<description>i tryed this code, for horizontal scrollbar, 
&lt;pre lang=&quot;matlab&quot;&gt;
jViewPort = jScrollPane.getViewport;
jEditbox = jViewPort.getComponent(0);
jEditbox.setWrapping(false);  % do *NOT* use set(...)!!!
newPolicy = jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
set(jScrollPane,&#039;HorizontalScrollBarPolicy&#039;,newPolicy);
&lt;/pre&gt;

but am getting this error:
?? No appropriate method, property, or field HORIZONTAL_SCROLLBAR_AS_NEEDED for class javahandle_withcallbacks.com.mathworks.hg.peer.utils.UIScrollPane.

Error in ==&gt; blblblb at 8
newPolicy = jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;</description>
		<content:encoded><![CDATA[<p>i tryed this code, for horizontal scrollbar,</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jViewPort = jScrollPane.<span style="">getViewport</span>;
jEditbox = jViewPort.<span style="">getComponent</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
jEditbox.<span style="">setWrapping</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% do *NOT* use set(...)!!!</span>
newPolicy = jScrollPane.<span style="">HORIZONTAL_SCROLLBAR_AS_NEEDED</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jScrollPane,<span style="color:#A020F0;">'HorizontalScrollBarPolicy'</span>,newPolicy<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>but am getting this error:<br />
?? No appropriate method, property, or field HORIZONTAL_SCROLLBAR_AS_NEEDED for class javahandle_withcallbacks.com.mathworks.hg.peer.utils.UIScrollPane.</p>
<p>Error in ==> blblblb at 8<br />
newPolicy = jScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carrie Kimbel</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-7075</link>
		<dc:creator>Carrie Kimbel</dc:creator>
		<pubDate>Wed, 10 Feb 2010 17:30:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-7075</guid>
		<description>Sorry.  Just a typo in my post.  I tried ...AS_NEEDED and ..._NEVER in my code - no luck, but the numbers work great.  Thanks.</description>
		<content:encoded><![CDATA[<p>Sorry.  Just a typo in my post.  I tried &#8230;AS_NEEDED and &#8230;_NEVER in my code &#8211; no luck, but the numbers work great.  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yair Altman</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-7073</link>
		<dc:creator>Yair Altman</dc:creator>
		<pubDate>Wed, 10 Feb 2010 16:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-7073</guid>
		<description>@Carrie - it&#039;s VERTICAL_SCROLLBAR_NEVER (without the &quot;_AS_&quot;). Only VERTICAL_SCROLLBAR_AS_NEEDED has an &quot;_AS_&quot;.</description>
		<content:encoded><![CDATA[<p>@Carrie &#8211; it&#8217;s VERTICAL_SCROLLBAR_NEVER (without the &#8220;_AS_&#8221;). Only VERTICAL_SCROLLBAR_AS_NEEDED has an &#8220;_AS_&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carrie Kimbel</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-7072</link>
		<dc:creator>Carrie Kimbel</dc:creator>
		<pubDate>Wed, 10 Feb 2010 16:50:20 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-7072</guid>
		<description>Thanks Yair.  Sorry I didn&#039;t see your post before I posted my final solution.  I didn&#039;t mean to seem ungrateful for your response.</description>
		<content:encoded><![CDATA[<p>Thanks Yair.  Sorry I didn&#8217;t see your post before I posted my final solution.  I didn&#8217;t mean to seem ungrateful for your response.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carrie Kimbel</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-7070</link>
		<dc:creator>Carrie Kimbel</dc:creator>
		<pubDate>Wed, 10 Feb 2010 16:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-7070</guid>
		<description>Found the answer.  Well, first I was trying to do this on the wrong edit control in my code - needed to do it on a multiline edit control.  

Second, when using the findjobj, it returned a 1x2 matrix of objects.  Turned out the UIScrollPane was the second object in the matrix, so to set the scrollbar, I did:

&lt;pre lang=&quot;matlab&quot;&gt;
set(set(jScrollPane(2), &#039;VerticalScrollBarPolicy&#039;, 21);
&lt;/pre&gt;

Of note, Matlab said &quot;No appropriate method, property, or field ... when I tried to use jScrollPane(2).VERTICAL_SCROLLBAR_AS_NEVER instead of 21.</description>
		<content:encoded><![CDATA[<p>Found the answer.  Well, first I was trying to do this on the wrong edit control in my code &#8211; needed to do it on a multiline edit control.  </p>
<p>Second, when using the findjobj, it returned a 1&#215;2 matrix of objects.  Turned out the UIScrollPane was the second object in the matrix, so to set the scrollbar, I did:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jScrollPane<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'VerticalScrollBarPolicy'</span>, <span style="color: #33f;">21</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Of note, Matlab said &#8220;No appropriate method, property, or field &#8230; when I tried to use jScrollPane(2).VERTICAL_SCROLLBAR_AS_NEVER instead of 21.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yair Altman</title>
		<link>http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/comment-page-1/#comment-7068</link>
		<dc:creator>Yair Altman</dc:creator>
		<pubDate>Wed, 10 Feb 2010 16:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=994#comment-7068</guid>
		<description>EditTextPeer$hgTextField is the single-line edit-box component, which does not have scrollbars. This is expected, since you ran &lt;b&gt;&lt;i&gt;findjobj&lt;/i&gt;&lt;/b&gt; immediately after creating your editbox as a single-line control. To turn the control to multi-line, you need to set the control&#039;s &lt;b&gt;Max&lt;/b&gt; property to a value greater than 1. If you now run &lt;b&gt;&lt;i&gt;findjobj&lt;/i&gt;&lt;/b&gt; you&#039;ll see EditTextPeer$hgTextEditMultiline, which does indeed contain scrollbars.</description>
		<content:encoded><![CDATA[<p>EditTextPeer$hgTextField is the single-line edit-box component, which does not have scrollbars. This is expected, since you ran <b><i>findjobj</i></b> immediately after creating your editbox as a single-line control. To turn the control to multi-line, you need to set the control&#8217;s <b>Max</b> property to a value greater than 1. If you now run <b><i>findjobj</i></b> you&#8217;ll see EditTextPeer$hgTextEditMultiline, which does indeed contain scrollbars.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
