<?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: Uicontrol callbacks</title> <atom:link href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Mon, 21 May 2012 11:05:42 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>By: Keith</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-76323</link> <dc:creator>Keith</dc:creator> <pubDate>Sat, 03 Mar 2012 01:24:25 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-76323</guid> <description>I&#039;ve got a uicontrol popup menu (not shown below) and an edit uicontrol (shown here) the default text on the edit text box is &#039;User Types Text Here&#039;  I want this to disappear (set the string to []) whenever the user clicks on the edit text box, and reappear (set the string to the default text) if they deselect (by clicking something else) the textbox and the string is still [].  Also I want the strings on two push buttons (accept and discard) to change appropriately (for example their string=&#039; &#039; if the string of the edit text box is the default string or empty and display &#039;Accept text&#039; and &#039;Discard text&#039;, there&#039;s also &#039;Accept file&#039; and &#039;Discard file&#039; strings depending whether a &#039;fill with...&#039; popup menu is set to &#039;fill with text&#039; or &#039;fill with file&#039; and there are a few other options too) some code fragments are belowthe problem I was having was that PostSet listeners of the uicontrols &#039;Selected&#039; property aren&#039;t triggering and my attempt to use the java (via your findjobj function aren&#039;t working either) maybe I&#039;m doing it wrong
changes to the string of the edit text box aren&#039;t triggering PostSet listeners either (at least not until I click somewhere other than the editable text box, which is too late, I want the label of the accept discard buttons to appear before they click somewhere else)Can you help me?Thanks,Keith&lt;pre lang=&#039;matlab&#039;&gt;
function make_user_text(hSynLowerLeftPanel,UserTextPos,WXWYInches,...
usertextstate)
SYNUD=getSynopsisUserData();
GUIFont=SYNUD.Preferences.GUIFont;
UserEditBackColor=SYNUD.UserEdit.Color.Back;
WYButtonNorm=min(0.3/WXWYInches(2),UserTextPos(4)/3);
UserTextPos(4)=UserTextPos(4)-WYButtonNorm;
UTUD.DefaultString=&#039;User Types Text Here&#039;;
hUserText=uicontrol(&#039;Parent&#039;,hSynLowerLeftPanel,&#039;style&#039;,&#039;edit&#039;,...
&#039;units&#039;,&#039;normalized&#039;,&#039;position&#039;,UserTextPos,...
&#039;Tag&#039;,&#039;SynopsisUserText&#039;,&#039;Min&#039;,1,&#039;Max&#039;,1000,...
&#039;FontName&#039;,GUIFont.Name,&#039;FontSize&#039;,GUIFont.Size,...
&#039;BackgroundColor&#039;,UserEditBackColor);
jUserText=findjobj(hUserText)
jUserText.FocusGainedCallback=@userTextSelectCallback;
jUserText.FocusLostCallback=@userTextDeselectCallback;
UTUD.hhUserText=handle(hUserText)
UTUD.hUserTextString=findprop(UTUD.hhUserText,&#039;String&#039;);
UTUD.hListenUserTextString=handle.listener(UTUD.hhUserText,...
UTUD.hUserTextString,&#039;PropertyPostSet&#039;,...
&#039;listenerCallbackToSetAcceptDiscardLabels()&#039;);
set(hUserText,&#039;UserData&#039;,UTUD);
....
endfunction userTextSelectCallback()
%this needs to trigger whenever the user selects the user text box (an
%edit uicontrol)
disp(&#039;userTextSelectCallback()&#039;);
hUserText=findobj(&#039;Tag&#039;,&#039;SynopsisUserText&#039;);
userTextString=get(hUserText,&#039;String&#039;);
UTUD=get(hUserText,&#039;UserData&#039;);
if(strcmpi(userTextString,UTUD.DefaultString))
%if/when you select the userText box and it has the default string
%(&quot;User Types Text Here&quot;) then this removes the default string
%so the user doesn&#039;t have to backspace it away
set(hUserText,&#039;String&#039;,[]);
userTextString=[];
end
endfunction userTextDeselectCallback()
%this needs to trigger whenever the user deselects the user text box
%(an edit uicontrol)
disp(&#039;userTextDeselectCallback()&#039;);
hUserText=findobj(&#039;Tag&#039;,&#039;SynopsisUserText&#039;);
userTextString=get(hUserText,&#039;String&#039;);
UTUD=get(hUserText,&#039;UserData&#039;);
if(isempty(userTextString))
%if/when you unselect (click anything else) user edit text box and
%the user edit text box string is empty then this resets the string
%to the default &quot;User Types Text Here&quot; String
set(hUserText,&#039;String&#039;,UTUD.DefaultString);
end
endfunction listenerCallbackToSetAcceptDiscardLabels()
%this function assigns the appropriate labels to the &#039;Accept ...&#039; and
%&#039;Discard ...&#039; pushbuttons, where appropriate means:
%&#039; &#039; if the user text box isn&#039;t supposed to be receiving instructions
%  OR
%&#039;... text&#039; if the &#039;fill with ...&#039; popupmenu is set to &#039;fill with text&#039;
%  OR
%&#039;... file&#039; if the &#039;fill with ...&#039; popupmenu is set to &#039;fill with file&#039;
hUserText=findobj(&#039;Tag&#039;,&#039;SynopsisUserText&#039;);
userTextString=get(hUserText,&#039;String&#039;);
UTUD=get(hUserText,&#039;UserData&#039;);
hAcceptTextOrFilePush=findobj(&#039;Tag&#039;,&#039;SynopsisAcceptTextFilePush&#039;);
hDiscardTextOrFilePush=findobj(&#039;Tag&#039;,&#039;SynopsisDiscardTextFilePush&#039;);
if(isempty(userTextString)&#124;&#124;strcmpi(userTextString,UTUD.DefaultString))
set(hAcceptTextOrFilePush,&#039;String&#039;,&#039; &#039;);
set(hDiscardTextOrFilePush,&#039;String&#039;,&#039; &#039;);
else
disp(&#039;listenerCallbackToSetAcceptDiscardLabels&#039;)
hFillWithPopup=findobj(&#039;Tag&#039;,&#039;SynopsisFillWithPopup&#039;);
FWUD=get(hFillWithPopup,&#039;UserData&#039;);
fwvalue=get(hFillWithPopup,&#039;value&#039;)
fwstring=get(hFillWithPopup,&#039;string&#039;)
fwstring=fwstring{fwvalue};
if(strcmpi(fwstring,FWUD.String{2}))
%fill with text so set the accept button to &#039;accept text&#039;,
%and the discard button to &#039;discard text&#039;
ATFUD=get(hAcceptTextOrFilePush,&#039;UserData&#039;);
set(hAcceptTextOrFilePush,&#039;String&#039;,ATFUD.String{1});
DTFUD=get(hDiscardTextOrFilePush,&#039;UserData&#039;);
set(hDiscardTextOrFilePush,&#039;String&#039;,DTFUD.String{1});
elseif(strcmpi(fwstring,FWUD.String{3}))
%fill with file so set the accept button to &#039;accept file&#039;,
%and the discard button to &#039;discard file&#039;
ATFUD=get(hAcceptTextOrFilePush,&#039;UserData&#039;);
set(hAcceptTextOrFilePush,&#039;String&#039;,ATFUD.String{2});
DTFUD=get(hDiscardTextOrFilePush,&#039;UserData&#039;);
set(hDiscardTextOrFilePush,&#039;String&#039;,DTFUD.String{2});
else
%fill with ... or &#039; &#039;
set(hAcceptTextOrFilePush,&#039;String&#039;,&#039; &#039;);
set(hDiscardTextOrFilePush,&#039;String&#039;,&#039; &#039;);
end
end
end
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>I&#8217;ve got a uicontrol popup menu (not shown below) and an edit uicontrol (shown here) the default text on the edit text box is &#8216;User Types Text Here&#8217;  I want this to disappear (set the string to []) whenever the user clicks on the edit text box, and reappear (set the string to the default text) if they deselect (by clicking something else) the textbox and the string is still [].  Also I want the strings on two push buttons (accept and discard) to change appropriately (for example their string=&#8217; &#8216; if the string of the edit text box is the default string or empty and display &#8216;Accept text&#8217; and &#8216;Discard text&#8217;, there&#8217;s also &#8216;Accept file&#8217; and &#8216;Discard file&#8217; strings depending whether a &#8216;fill with&#8230;&#8217; popup menu is set to &#8216;fill with text&#8217; or &#8216;fill with file&#8217; and there are a few other options too) some code fragments are below</p><p>the problem I was having was that PostSet listeners of the uicontrols &#8216;Selected&#8217; property aren&#8217;t triggering and my attempt to use the java (via your findjobj function aren&#8217;t working either) maybe I&#8217;m doing it wrong<br
/> changes to the string of the edit text box aren&#8217;t triggering PostSet listeners either (at least not until I click somewhere other than the editable text box, which is too late, I want the label of the accept discard buttons to appear before they click somewhere else)</p><p>Can you help me?</p><p>Thanks,</p><p>Keith</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> make_user_text<span style="color: #080;">&#40;</span>hSynLowerLeftPanel,UserTextPos,WXWYInches,<span style="color: #F0F;">...</span>
    <span style="">usertextstate</span><span style="color: #080;">&#41;</span>
    SYNUD=getSynopsisUserData<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
    GUIFont=SYNUD.<span style="">Preferences</span>.<span style="">GUIFont</span>;
    UserEditBackColor=SYNUD.<span style="">UserEdit</span>.<span style="">Color</span>.<span style="">Back</span>;
&nbsp;
    WYButtonNorm=<span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.3</span>/WXWYInches<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,UserTextPos<span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span>/<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>;
    UserTextPos<span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span>=UserTextPos<span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span>-WYButtonNorm;
    UTUD.<span style="">DefaultString</span>=<span style="color:#A020F0;">'User Types Text Here'</span>;
    hUserText=<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Parent'</span>,hSynLowerLeftPanel,<span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>,<span style="color: #F0F;">...</span>
        <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'normalized'</span>,<span style="color:#A020F0;">'position'</span>,UserTextPos,<span style="color: #F0F;">...</span>
        <span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisUserText'</span>,<span style="color:#A020F0;">'Min'</span>,<span style="color: #33f;">1</span>,<span style="color:#A020F0;">'Max'</span>,<span style="color: #33f;">1000</span>,<span style="color: #F0F;">...</span>
        <span style="color:#A020F0;">'FontName'</span>,GUIFont.<span style="">Name</span>,<span style="color:#A020F0;">'FontSize'</span>,GUIFont.<span style="color: #0000FF;">Size</span>,<span style="color: #F0F;">...</span>
        <span style="color:#A020F0;">'BackgroundColor'</span>,UserEditBackColor<span style="color: #080;">&#41;</span>;    
    jUserText=findjobj<span style="color: #080;">&#40;</span>hUserText<span style="color: #080;">&#41;</span>
    jUserText.<span style="">FocusGainedCallback</span>=@userTextSelectCallback;
    jUserText.<span style="">FocusLostCallback</span>=@userTextDeselectCallback;
&nbsp;
    UTUD.<span style="">hhUserText</span>=handle<span style="color: #080;">&#40;</span>hUserText<span style="color: #080;">&#41;</span>
    UTUD.<span style="">hUserTextString</span>=<span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>UTUD.<span style="">hhUserText</span>,<span style="color:#A020F0;">'String'</span><span style="color: #080;">&#41;</span>;
    UTUD.<span style="">hListenUserTextString</span>=<span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>UTUD.<span style="">hhUserText</span>,<span style="color: #F0F;">...</span>
        <span style="">UTUD</span>.<span style="">hUserTextString</span>,<span style="color:#A020F0;">'PropertyPostSet'</span>,<span style="color: #F0F;">...</span>
        <span style="color:#A020F0;">'listenerCallbackToSetAcceptDiscardLabels()'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'UserData'</span>,UTUD<span style="color: #080;">&#41;</span>;
<span style="color: #F0F;">...</span>.
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">function</span> userTextSelectCallback<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">%this needs to trigger whenever the user selects the user text box (an </span>
    <span style="color: #228B22;">%edit uicontrol)</span>
    <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'userTextSelectCallback()'</span><span style="color: #080;">&#41;</span>;
    hUserText=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisUserText'</span><span style="color: #080;">&#41;</span>;
    userTextString=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'String'</span><span style="color: #080;">&#41;</span>;
    UTUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;    
    <span style="color: #0000FF;">if</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmpi</span><span style="color: #080;">&#40;</span>userTextString,UTUD.<span style="">DefaultString</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
        <span style="color: #228B22;">%if/when you select the userText box and it has the default string</span>
        <span style="color: #228B22;">%(&quot;User Types Text Here&quot;) then this removes the default string </span>
        <span style="color: #228B22;">%so the user doesn't have to backspace it away</span>
        <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'String'</span>,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
        userTextString=<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">function</span> userTextDeselectCallback<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">%this needs to trigger whenever the user deselects the user text box </span>
    <span style="color: #228B22;">%(an edit uicontrol)</span>
    <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'userTextDeselectCallback()'</span><span style="color: #080;">&#41;</span>;
    hUserText=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisUserText'</span><span style="color: #080;">&#41;</span>;
    userTextString=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'String'</span><span style="color: #080;">&#41;</span>;
    UTUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">if</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>userTextString<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>        
        <span style="color: #228B22;">%if/when you unselect (click anything else) user edit text box and</span>
        <span style="color: #228B22;">%the user edit text box string is empty then this resets the string</span>
        <span style="color: #228B22;">%to the default &quot;User Types Text Here&quot; String</span>
        <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'String'</span>,UTUD.<span style="">DefaultString</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">function</span> listenerCallbackToSetAcceptDiscardLabels<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">%this function assigns the appropriate labels to the 'Accept ...' and</span>
    <span style="color: #228B22;">%'Discard ...' pushbuttons, where appropriate means:</span>
    <span style="color: #228B22;">%' ' if the user text box isn't supposed to be receiving instructions</span>
    <span style="color: #228B22;">%  OR</span>
    <span style="color: #228B22;">%'... text' if the 'fill with ...' popupmenu is set to 'fill with text'</span>
    <span style="color: #228B22;">%  OR</span>
    <span style="color: #228B22;">%'... file' if the 'fill with ...' popupmenu is set to 'fill with file'</span>
&nbsp;
    hUserText=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisUserText'</span><span style="color: #080;">&#41;</span>;
    userTextString=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'String'</span><span style="color: #080;">&#41;</span>;
    UTUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUserText,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
    hAcceptTextOrFilePush=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisAcceptTextFilePush'</span><span style="color: #080;">&#41;</span>;
    hDiscardTextOrFilePush=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisDiscardTextFilePush'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">if</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>userTextString<span style="color: #080;">&#41;</span><span style="color: #F0F;">||</span>strcmpi<span style="color: #080;">&#40;</span>userTextString,UTUD.<span style="">DefaultString</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
        <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">' '</span><span style="color: #080;">&#41;</span>;
        <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">' '</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">else</span>
        <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'listenerCallbackToSetAcceptDiscardLabels'</span><span style="color: #080;">&#41;</span>
        hFillWithPopup=<span style="color: #0000FF;">findobj</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'SynopsisFillWithPopup'</span><span style="color: #080;">&#41;</span>;
        FWUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFillWithPopup,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
        fwvalue=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFillWithPopup,<span style="color:#A020F0;">'value'</span><span style="color: #080;">&#41;</span>
        fwstring=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFillWithPopup,<span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>
        fwstring=fwstring<span style="color: #080;">&#123;</span>fwvalue<span style="color: #080;">&#125;</span>;
        <span style="color: #0000FF;">if</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmpi</span><span style="color: #080;">&#40;</span>fwstring,FWUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
            <span style="color: #228B22;">%fill with text so set the accept button to 'accept text',</span>
            <span style="color: #228B22;">%and the discard button to 'discard text'</span>
            ATFUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'String'</span>,ATFUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
            DTFUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'String'</span>,DTFUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;                
        <span style="color: #0000FF;">elseif</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmpi</span><span style="color: #080;">&#40;</span>fwstring,FWUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">3</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
            <span style="color: #228B22;">%fill with file so set the accept button to 'accept file',</span>
            <span style="color: #228B22;">%and the discard button to 'discard file'</span>
            ATFUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'String'</span>,ATFUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
            DTFUD=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'String'</span>,DTFUD.<span style="">String</span><span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;                                
        <span style="color: #0000FF;">else</span>
            <span style="color: #228B22;">%fill with ... or ' '</span>
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAcceptTextOrFilePush,<span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">' '</span><span style="color: #080;">&#41;</span>;
            <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDiscardTextOrFilePush,<span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">' '</span><span style="color: #080;">&#41;</span>;
        <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>]]></content:encoded> </item> <item><title>By: Matlab-Java memory leaks, performance &#124; Undocumented Matlab</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-71620</link> <dc:creator>Matlab-Java memory leaks, performance &#124; Undocumented Matlab</dc:creator> <pubDate>Fri, 20 Jan 2012 11:52:29 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-71620</guid> <description>[...] a Matlab callback that gets invoked multiple times per second by a Java object (see related articles here and here). Each time the Matlab callback function is invoked, it reads the event information [...]</description> <content:encoded><![CDATA[<p>[...] a Matlab callback that gets invoked multiple times per second by a Java object (see related articles here and here). Each time the Matlab callback function is invoked, it reads the event information [...]</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-69592</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Thu, 05 Jan 2012 10:05:52 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-69592</guid> <description>@Dave - this is correct. Matlab callbacks always send the originating object (in your case, a button which is actually an MJButton control) as the first parameter, and an eventData object as the second parameter. in eventData you can find information regarding the event, for example whether the button was clicked or right-clicked etc.</description> <content:encoded><![CDATA[<p>@Dave &#8211; this is correct. Matlab callbacks always send the originating object (in your case, a button which is actually an MJButton control) as the first parameter, and an eventData object as the second parameter. in eventData you can find information regarding the event, for example whether the button was clicked or right-clicked etc.</p> ]]></content:encoded> </item> <item><title>By: Dave</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-69244</link> <dc:creator>Dave</dc:creator> <pubDate>Tue, 03 Jan 2012 15:35:01 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-69244</guid> <description>Yair, your knowledge is incredible, thank you for sharing.
Please excuse my lack of understanding but it seems that whenever I try to use a callback it sends &lt;i&gt;javahandle_withcallbacks.com.mathworks.mwswing.MJButton&lt;/i&gt; as the first parameter.
&lt;pre lang=&quot;matlab&quot;&gt;
function badprogrammingpracticehFig = figure(&#039;position&#039;, [300 300 600 400]);
jbt = com.mathworks.mwswing.MJButton(&#039;click me&#039;);
jbt.setBorder([])
jbt.setBackground(java.awt.Color.white);
jbt.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
jbt.setFlyOverAppearance(1);
bob = [1 2 3]
jbtPosition = [0.1 0.1 0.3 0.3]
[dummy,btContainer] = javacomponent(jbt,[0 0 1 1],hFig);
set(btContainer, &#039;Units&#039;,&#039;Norm&#039;, &#039;Position&#039;,jbtPosition);
hbt = handle(jbt,&#039;CallbackProperties&#039;);
set(hbt,&#039;ActionPerformedCallback&#039;,@dosomething);function [mean,stdev] = dosomething(x,y)
x
&lt;/pre&gt;output:bob =
1     2     3
jbtPosition =
0.1000    0.1000    0.3000    0.3000
x =
javahandle_withcallbacks.com.mathworks.mwswing.MJButton
&gt;&gt;</description> <content:encoded><![CDATA[<p>Yair, your knowledge is incredible, thank you for sharing.<br
/> Please excuse my lack of understanding but it seems that whenever I try to use a callback it sends <i>javahandle_withcallbacks.com.mathworks.mwswing.MJButton</i> as the first parameter.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> badprogrammingpractice
&nbsp;
hFig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">300</span> <span style="color: #33f;">300</span> <span style="color: #33f;">600</span> <span style="color: #33f;">400</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
jbt = com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'click me'</span><span style="color: #080;">&#41;</span>;
jbt.<span style="">setBorder</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>
jbt.<span style="">setBackground</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Color</span>.<span style="">white</span><span style="color: #080;">&#41;</span>;
jbt.<span style="">setCursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span>.<span style="">getPredefinedCursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span>.<span style="">HAND_CURSOR</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
jbt.<span style="">setFlyOverAppearance</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
bob = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">2</span> <span style="color: #33f;">3</span><span style="color: #080;">&#93;</span>
jbtPosition = <span style="color: #080;">&#91;</span><span style="color: #33f;">0.1</span> <span style="color: #33f;">0.1</span> <span style="color: #33f;">0.3</span> <span style="color: #33f;">0.3</span><span style="color: #080;">&#93;</span>
<span style="color: #080;">&#91;</span>dummy,btContainer<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span>jbt,<span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,hFig<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>btContainer, <span style="color:#A020F0;">'Units'</span>,<span style="color:#A020F0;">'Norm'</span>, <span style="color:#A020F0;">'Position'</span>,jbtPosition<span style="color: #080;">&#41;</span>;
hbt = handle<span style="color: #080;">&#40;</span>jbt,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hbt,<span style="color:#A020F0;">'ActionPerformedCallback'</span>,@dosomething<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span><span style="color: #0000FF;">mean</span>,stdev<span style="color: #080;">&#93;</span> = dosomething<span style="color: #080;">&#40;</span>x,y<span style="color: #080;">&#41;</span>
x</pre></div></div><p>output:</p><p>bob =<br
/> 1     2     3<br
/> jbtPosition =<br
/> 0.1000    0.1000    0.3000    0.3000<br
/> x =<br
/> javahandle_withcallbacks.com.mathworks.mwswing.MJButton<br
/> &gt;&gt;</p> ]]></content:encoded> </item> <item><title>By: Janos Marki</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-31631</link> <dc:creator>Janos Marki</dc:creator> <pubDate>Sun, 30 Jan 2011 14:27:16 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-31631</guid> <description>Update to previous: it now works. I think the problem was with the callback getting overwritten for some reason (only possible culprit: pcolor function). By inserting the callback handle again, it works without a hitch. Sorry for the hassle.Janos&lt;pre lang=&quot;matlab&quot;&gt;
figure(a111)
set(gcf,&#039;WindowKeyPressFcn&#039;,@scalSet)
waitfor(a111,&#039;UserData&#039;,&#039;Done&#039;);
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>Update to previous: it now works. I think the problem was with the callback getting overwritten for some reason (only possible culprit: pcolor function). By inserting the callback handle again, it works without a hitch. Sorry for the hassle.</p><p>Janos</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span>a111<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'WindowKeyPressFcn'</span>,@scalSet<span style="color: #080;">&#41;</span>
waitfor<span style="color: #080;">&#40;</span>a111,<span style="color:#A020F0;">'UserData'</span>,<span style="color:#A020F0;">'Done'</span><span style="color: #080;">&#41;</span>;</pre></div></div>]]></content:encoded> </item> <item><title>By: Janos Marki</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-31614</link> <dc:creator>Janos Marki</dc:creator> <pubDate>Sun, 30 Jan 2011 12:12:49 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-31614</guid> <description>Hi,I have a problem that I can&#039;t seem to solve, and I can&#039;t find the info.I execute a number of commands culminating in a plot. At this point, I need to intervene manually, which I thought of doing via the WindowKeyPressFcn callback of the figure I plotted in. Once done, I would like script execution to resume.However, whatever way I use to stop keyboard execution (keyboard, waitfor(figHand), no matter what I do, instead of the figure&#039;s callback (scalSet.m) activating, the pressed key appears in the command window (i.e. I cannot make the figure the &quot;active&quot; object so the pressed key goes into it). It seems to me like this goes against the notion of having ready code, running the GUI, and then interacting with it (as interaction would already start whilst the script is run). Is this me trying to use Matlab in ways it has not been intended to work? Can it be done, or should I just do it differently?&lt;pre lang=&quot;matlab&quot;&gt;
a111=figure(&#039;WindowKeyPressFcn&#039;,@scalSet);
waitfor(a111,&#039;UserData&#039;,&#039;Done&#039;);
&lt;/pre&gt;
...and the idea was to have one key (d) for the &quot;Done&quot; state in the callback function (waitfor would let the script carry on once this is triggered), which looks like this:
&lt;pre lang=&quot;matlab&quot;&gt;
function scalSet(src,eventdata)
%function scalSet(src,eventdata)
%
%Function used to set scales with the mouse manually on plots with a colorbar
%Press &#039;r&#039; to narrow the scale by clicking two values on the
%colorbar with the mouse
%
%Press &#039;w&#039; to double the range
%
%enter set(gcf,&#039;WindowKeyPressFcn&#039;,@scalSet) to add it to figures a
%posteriori%we want to make the colorbar scaling smaller
if strcmp(eventdata.Character,&#039;r&#039;)
scval=ginput(2);
chs=get(src,&#039;Children&#039;);
for k=1:length(chs)
nu=get(chs(k),&#039;Type&#039;);
if strcmp(nu,&#039;axes&#039;)
nu2=get(chs(k),&#039;Tag&#039;);
if ~strcmp(nu2,&#039;Colorbar&#039;)
caxis(chs(k),[sort(scval(:,2))&#039;])
end
end
end
end%we want to widen it
if strcmp(eventdata.Character,&#039;w&#039;)
scval=caxis;
wid=scval(2)-scval(1);
caxis([scval(1)-wid scval(2)+wid])
end%we are done
if strcmp(eventdata.Character,&#039;d&#039;)
set(src,&#039;UserData&#039;,&#039;Done&#039;)
end
&lt;/pre&gt;Thanks!
Janos</description> <content:encoded><![CDATA[<p>Hi,</p><p>I have a problem that I can&#8217;t seem to solve, and I can&#8217;t find the info.</p><p>I execute a number of commands culminating in a plot. At this point, I need to intervene manually, which I thought of doing via the WindowKeyPressFcn callback of the figure I plotted in. Once done, I would like script execution to resume.</p><p>However, whatever way I use to stop keyboard execution (keyboard, waitfor(figHand), no matter what I do, instead of the figure&#8217;s callback (scalSet.m) activating, the pressed key appears in the command window (i.e. I cannot make the figure the &#8220;active&#8221; object so the pressed key goes into it). It seems to me like this goes against the notion of having ready code, running the GUI, and then interacting with it (as interaction would already start whilst the script is run). Is this me trying to use Matlab in ways it has not been intended to work? Can it be done, or should I just do it differently?</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a111=<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'WindowKeyPressFcn'</span>,@scalSet<span style="color: #080;">&#41;</span>; 
waitfor<span style="color: #080;">&#40;</span>a111,<span style="color:#A020F0;">'UserData'</span>,<span style="color:#A020F0;">'Done'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>&#8230;and the idea was to have one key (d) for the &#8220;Done&#8221; state in the callback function (waitfor would let the script carry on once this is triggered), which looks like this:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> scalSet<span style="color: #080;">&#40;</span>src,eventdata<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%function scalSet(src,eventdata)</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%Function used to set scales with the mouse manually on plots with a colorbar</span>
<span style="color: #228B22;">%Press 'r' to narrow the scale by clicking two values on the</span>
<span style="color: #228B22;">%colorbar with the mouse</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%Press 'w' to double the range</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%enter set(gcf,'WindowKeyPressFcn',@scalSet) to add it to figures a</span>
<span style="color: #228B22;">%posteriori</span>
&nbsp;
<span style="color: #228B22;">%we want to make the colorbar scaling smaller</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>eventdata.<span style="">Character</span>,<span style="color:#A020F0;">'r'</span><span style="color: #080;">&#41;</span>
   scval=<span style="color: #0000FF;">ginput</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
   chs=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>src,<span style="color:#A020F0;">'Children'</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">for</span> k=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>chs<span style="color: #080;">&#41;</span>
       nu=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>chs<span style="color: #080;">&#40;</span>k<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Type'</span><span style="color: #080;">&#41;</span>;
       <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>nu,<span style="color:#A020F0;">'axes'</span><span style="color: #080;">&#41;</span>
         nu2=<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>chs<span style="color: #080;">&#40;</span>k<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Tag'</span><span style="color: #080;">&#41;</span>;
           <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>nu2,<span style="color:#A020F0;">'Colorbar'</span><span style="color: #080;">&#41;</span>
               <span style="color: #0000FF;">caxis</span><span style="color: #080;">&#40;</span>chs<span style="color: #080;">&#40;</span>k<span style="color: #080;">&#41;</span>,<span style="color: #080;">&#91;</span><span style="color: #0000FF;">sort</span><span style="color: #080;">&#40;</span>scval<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>'<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>
           <span style="color: #0000FF;">end</span>
       <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>   
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">%we want to widen it</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>eventdata.<span style="">Character</span>,<span style="color:#A020F0;">'w'</span><span style="color: #080;">&#41;</span>
   scval=<span style="color: #0000FF;">caxis</span>;
   wid=scval<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>-scval<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">caxis</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>scval<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>-wid scval<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>+wid<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">%we are done</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>eventdata.<span style="">Character</span>,<span style="color:#A020F0;">'d'</span><span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>src,<span style="color:#A020F0;">'UserData'</span>,<span style="color:#A020F0;">'Done'</span><span style="color: #080;">&#41;</span> 
<span style="color: #0000FF;">end</span></pre></div></div><p>Thanks!<br
/> Janos</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-24937</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Tue, 07 Dec 2010 19:59:06 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-24937</guid> <description>@Sean - take a look at: http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/Related articles:
http://undocumentedmatlab.com/blog/figure-toolbar-components/
http://undocumentedmatlab.com/blog/figure-toolbar-customizations/- Yair</description> <content:encoded><![CDATA[<p>@Sean &#8211; take a look at: <a
href="http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/" rel="nofollow">http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/</a></p><p>Related articles:<br
/> <a
href="http://undocumentedmatlab.com/blog/figure-toolbar-components/" rel="nofollow">http://undocumentedmatlab.com/blog/figure-toolbar-components/</a><br
/> <a
href="http://undocumentedmatlab.com/blog/figure-toolbar-customizations/" rel="nofollow">http://undocumentedmatlab.com/blog/figure-toolbar-customizations/</a></p><p>- Yair</p> ]]></content:encoded> </item> <item><title>By: Sean Larkin</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-24931</link> <dc:creator>Sean Larkin</dc:creator> <pubDate>Tue, 07 Dec 2010 19:12:07 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-24931</guid> <description>I&#039;m trying to use findjobj to get the java handle for a toolbar uitogglebutton.  It does not find the handles for the button.  When I call the function like this:
findjobj;it finds the toolbar button.  Why is this and is there a way I can modify findjobj to directly find toolbar buttons?</description> <content:encoded><![CDATA[<p>I&#8217;m trying to use findjobj to get the java handle for a toolbar uitogglebutton.  It does not find the handles for the button.  When I call the function like this:<br
/> findjobj;</p><p>it finds the toolbar button.  Why is this and is there a way I can modify findjobj to directly find toolbar buttons?</p> ]]></content:encoded> </item> <item><title>By: iroln</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-22396</link> <dc:creator>iroln</dc:creator> <pubDate>Wed, 10 Nov 2010 21:11:15 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-22396</guid> <description>Thanks, Yair Altman!</description> <content:encoded><![CDATA[<p>Thanks, Yair Altman!</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/uicontrol-callbacks/#comment-22139</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Sun, 07 Nov 2010 22:40:23 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=223#comment-22139</guid> <description>@iroln and Donn - apparently all mouse actions are delegated to the AxisCanvas component, so simply set your callback on that component. It works for me on R2010b. Here&#039;s the complete code snippet:
&lt;pre lang=&quot;matlab&quot;&gt;
function TestMouseCallbacks()
hFig = figure();
warning(&#039;off&#039;,&#039;MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame&#039;);
drawnow;
jh = get(hFig, &#039;JavaFrame&#039;);
jf = jh.fFigureClient.getAxisComponent;  % note the change
jbh = handle(jf, &#039;CallbackProperties&#039;);
set(jbh, &#039;MouseWheelMovedCallback&#039;, @MousePressed)
end
function MousePressed(jObject, jEventData)
disp(&#039;Pressed&#039;)
end
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>@iroln and Donn &#8211; apparently all mouse actions are delegated to the AxisCanvas component, so simply set your callback on that component. It works for me on R2010b. Here&#8217;s the complete code snippet:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> TestMouseCallbacks<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
  hFig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'off'</span>,<span style="color:#A020F0;">'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame'</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">drawnow</span>;
  jh = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
  jf = jh.<span style="">fFigureClient</span>.<span style="">getAxisComponent</span>;  <span style="color: #228B22;">% note the change</span>
  jbh = handle<span style="color: #080;">&#40;</span>jf, <span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jbh, <span style="color:#A020F0;">'MouseWheelMovedCallback'</span>, @MousePressed<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">function</span> MousePressed<span style="color: #080;">&#40;</span>jObject, jEventData<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Pressed'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span></pre></div></div>]]></content:encoded> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           single
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-05-21 20:44:08 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/uicontrol-callbacks/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.767s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1337658248; expires=Wed, 22-May-2013 03:44:08 GMT; path=/
Link:               <http://undocumentedmatlab.com/?p=223>; rel=shortlink
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Tue, 22 May 2012 03:44:08 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Tue, 22 May 2012 04:44:08 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               3aaa304aef7c73a4ee0b398d3fb1c7b5
Content-Encoding:   gzip
-->
