Change static box text based on edit box selection
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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
See Also
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!