Prev: undefined function error in 2009a, but not in 2009b
Next: Need help for "Indexing cannot yield multiple results"
From: J Queue on 10 Feb 2010 14:06 A uicontrol pushbutton executes its callback when the mouse is RELEASED, rather than when it is PRESSED on the button. I need to have a button that executes the callback when the button is pressed. I tried a bunch of stuff and basically ended up writing my own button using uipanel (see below). This works, except that if I place text on the button (using uicontrol text), the text captures the mouse click. I tried using 'HitTest', 'off' and also tried to set a callback, but neither approach works. Any insight -- including another approach if you have one --- would be appreciated. Please post to the forum, as the e-mail address is temporary. Thanks! function mybutton set(gcf, 'DefaultUiControlUnits', 'norm') h = uipanel('Position', [0.1 0.1 0.1 0.1], ... 'BorderType', 'beveledout', ... 'ButtonDownFcn', @down) % This control will capture mouse clicks % I tried 'HitTest', 'off' and also 'Callback' @down % but neither worked uicontrol('Style', 'text', ... 'Parent', h, ... 'Position', [0.2 0.2 0.5 0.5], ... 'String', '1', ... 'FontSize', 12, ... 'FontWeight', 'bold'); function down(src, evt) set(h, 'BorderType', 'beveledin') set(gcf, 'WindowButtonUpFcn', @up); disp('*') end function up(src, evt) set(h, 'BorderType', 'beveledout') set(gcf, 'WindowButtonUpFcn', ''); end end
From: Yair Altman on 10 Feb 2010 18:15
"J Queue" <b3764718(a)uggsrock.com> wrote... > A uicontrol pushbutton executes its callback when the mouse is RELEASED, rather than when it is PRESSED on the button. I need to have a button that executes the callback when the button is pressed. This is possible using the uicontrol's underlying Java object, as explained here: http://undocumentedmatlab.com/blog/uicontrol-callbacks/ Simply download the FindJObj utility from the File Exchange ( http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects ) and then: hControl = uicontrol(...); jControl = findjobj(hControl); set(jControl,'KeyPressedCallback',@myMatlabCallbackFunction); The FindJObj utility is explained here: http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/ Yair Altman http://UndocumentedMatlab.com |