How do I make a text box in GUI that updates immediately when slider is moved?

6 views (last 30 days)
I apologize if this is easy to figure out, but I'm exhausted on this Friday evening. I'm new to making GUIs. I want to have a GUI in which there is a slider and whenever the user changes the slider position, a text box immediately takes the value in the slider and displays it. In other words, I don't want there to be any guesses as to what value the slider is at, I want it to be displayed as soon as the slider position is changed. How do I make this textbox update the value of the slider dynamically like that?
Thanks!

Accepted Answer

Geoff Hayes
Geoff Hayes on 8 Nov 2014
Alexei - see the solution from make GUI slider behave like iOS frame scroller which will tell you how to create a continuous value change listener for the slider. The only thing that ail be missing is how to update the text box which you can do by just modifying the slider1ContValCallback (from the link) as
function slider1ContValCallback(hFigure,eventdata)
% test it out - get the handles object and write the current value
% to the edit box
handles = guidata(hFigure);
sliderValue = get(handles.slider1,'Value');
set(handles.text1,'String',num2str(sliderValue));
The above assumes that text1 is the tag for the text box that you wish to update, and that slider1 is the tag for your slider.
Try it out and see what happens!
  1 Comment
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis on 9 Feb 2019
@ Geof Hayes : i just implemented your code but it updated numeric values instead of my text1's content sir. what should i do to update the content of text1 when i scroll up or down appropriately sir ?
please help

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!