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
Bachtiar Muhammad Lubis 2019년 2월 9일
@ 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