Change static box text based on edit box selection

2 views (last 30 days)
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.

Answers (1)

Meade
Meade on 26 May 2016
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 Comment
Drew Demmerle
Drew Demmerle on 1 Jun 2016
Edited: Drew Demmerle on 1 Jun 2016
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.

Sign in to comment.

Categories

Find more on Platform and License in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!