MATLAB Answers


Mouse Slider capability in uicontrol slider

Asked by Boris
on 25 Jan 2013

Hi all,

I have recently begun using MATLAB 2010b and have a question about using the mouse scroll wheel in guis.

I am working on a gui that has within it a uipanel with a 'slider' type uicontrol which scrolls through a number of axes. Everything is working properly, however I would like the slider to be able to be controlled by the scroll wheel on the mouse.

I searched extensively for functions that could implement this, but all I found was the WindowsScrollWheelFcn, which is for figure type objects, not uicontrol types. I do not think that the function would work for uicontrol sliders, but perhaps it does?

If anyone knows how to get the mouse scroll wheel to work for uicontrol sliders, I would really appreciate being pointed in the right direction. This is a relatively small part of the whole gui so I do not think it would be worth it for me to rewrite everything into a figure just to get the scroll wheel working, but I would be open to hearing such suggestions.

Thanks for the help, Boris



No products are associated with this question.

1 Answer

Answer by Jan Simon
on 25 Jan 2013

Yair's FEX: findjobj allows to access the underlying capabilities of the uicontrols:

hButton = uicontrol('style', 'slider');
jButton = findjobj(hButton);
jButton.MouseWheelMovedCallback = 'disp(clock)'

Now the moving the mouse wheel triggers the callback. But the slider must be the current object also, so you need to click on it at first.

The MouseMotionCallback of the figure can move the focus to the slider when the mouse is moved on top.

On the other hand, the WindowsScrollWheelFcn is not a bad idea also. Whenever the mouse is over the slider, let this callback move the slider. This is more direct then the indirection over the Java methods of the slider, although this is a contradiction to the actually clear object oriented structure of a GUI.

  1 Comment

on 28 Jan 2013

Thanks for the response Jan.

I have code implementing WindowScrollWheelFcn working now, however I have to create a new figure to use the function. From there I edit my slider position based off the scroll wheel movements inside the new figure.

The problem is that I want the scroll panel to move when the mouse is moved over the uicontrol slider, not some random figure that I am not even using. I tried making a WindowScrollWheelFcn callback in the uicontrol, but an error said that uicontrols do not have such a field.

So I guess my question is, is it possible to use the WindowScrollWheelFcn without having any figure, just uicontrol objects?

Thanks, Boris

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!