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

6 次查看(过去 30 天)
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!

采纳的回答

Geoff Hayes
Geoff Hayes 2014-11-8
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 个评论
Bachtiar Muhammad Lubis
@ 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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by