Change static box text based on edit box selection

조회 수: 1 (최근 30일)
Drew Demmerle
Drew Demmerle 2016년 5월 26일
편집: Drew Demmerle 2016년 6월 1일
So pretty new to GUI, and I have a program that has many variable inputs to set parameters (such as amperage) for a series of calculations that I will run later, but so my problem is that there isn't any room to put details about what data should be put into each edit box (call it editAmps) so my solution was to have a text box (text52) that would change it's value whenever an edit box was selected to be edited (so click on a editbox and details about that parameter show up in text52 and it does this for every different editbox). I know the set(handles.text52, 'String', 'Amperage, amps') but I don't know where to put it (I tried putting it in the editAmps_Callback and the editAmps_ButtonDownFcn, but either I didn't do it right or it is supposed to use something else)
Also note I have about 50 parameters who's details as at least as long as the amperage one (most longer) so making the window larger isn't going to accomplish anything.

답변 (1개)

Meade
Meade 2016년 5월 26일
Hey Drew, see if this example helps you out!
Just copy the whole thing, save it and run it.
function MyGUI
f = figure();
hEditBox = uicontrol('style','edit',...
'units','norm',...
'Position',[0.25 0.5 0.5 0.25],...
'String','I''m an EDIT BOX',...
'TooltipString','RIGHT Click Me to update the Static Text Box below!',...
'FontSize',14,...
'FontWeight','bold',...
'ButtonDownFcn',@editbox2textbox,... %'Callback' for keyboard enter
'Tag','hEditBox');
hTextBox = uicontrol('style','text',...
'units','norm',...
'Position',[0.25 0.20 0.5 0.1],...
'String','I''m a STATIC TEXT BOX',...
'TooltipString','I''m updated by clicking above↑',...
'FontSize',14,...
'FontWeight','bold',...
'ForegroundColor','r',...
'BackgroundColor','y',...
'Tag','hTextBox');
handles = guihandles(f); % It's important to save all your handles to a "guidata" struct
MyGUIdata.handles = handles;
guidata(f,MyGUIdata); % This is how you pass information from one GUI fnc to another
end
function editbox2textbox(hObj,~)
h = guidata(hObj); % You need to get the handles for your figure
someInfo = datestr(now); % A placeholder for the info you want updated
set(h.handles.hTextBox,'String',someInfo); %Update the textbox
end
  댓글 수: 1
Drew Demmerle
Drew Demmerle 2016년 6월 1일
편집: Drew Demmerle 2016년 6월 1일
So I have been trying to incorporate this into my code but I don't think I have a strong enough understanding to do it. I get rid of the beginning parts because I have already made the figure, text box and edit box(es) is GUIDE, so I don't need that code. Then I modify the names a bit so should work with my GUI to get:
function MyGUI
handles = guihandles(BTAm);
MyGUIdata.handles = handles;
guidata(BTAm,MyGUIdata);
end
function AmpsBox(hObj,~)
h = guidata(hObj);
someInfo = 'Amperage, amps';
set(h.handles.text52,'String',someInfo);
end
But this just returns an error saying " unexpected MATLAB operator" at a line about 150 lines down. Or if I try to put it in a different program and call it, it just does nothing. The program is called BTAm and I am trying to put in the callback for editAmps so it changes text52 when I select editAmps, though it also has to be repeatable for 49 other edit boxes that all modify text52. Also advice on how to implement the code into the callback would be helpful.

댓글을 달려면 로그인하십시오.

카테고리

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