Static Text Handle Creation

12 views (last 30 days)
Bryce
Bryce on 24 Jun 2014
Edited: Joseph Cheng on 24 Jun 2014
Hello All,
I have a hopefully quick and easy question for you guys that I need help answering. I have looked around for quite a while and it is my understanding that handles are not automatically created for static text boxes, at least those that are made in GUIDE, which mine is. I have created the callback function and in it there is a comment that says:
"handles empty - handles not created until after all CreateFcns called"
What I am trying to do is have an error come up if the user inputs an incorrect number in an editable text box. This will be done by first setting the Static Text visibility to off. I can already achieve this by writing "set(hObject, 'visible', 'off'); " in the callback function for the text box. However, using hObject is only possible within the callback for that function so I am trying to use the handle like from a normal push button: "set(handles.ErrorText, 'visible', 'on'); " to be created after a push button is pressed and it does not work.
If it is because of the fact that no handle has been created for it, could you help me learn how to make one because I can't figure it out.
Any help will be much appreciated. Thanks

Accepted Answer

Joseph Cheng
Joseph Cheng on 24 Jun 2014
Edited: Joseph Cheng on 24 Jun 2014
there should be a tag associated with the static text. default is "handles.text1", it doesn't create functions like the other uicontrols since it is usually just used as static text. so i am not sure what you're accomplishing with the set(hObject....) within the text box as that would turn the text box visibility off.
i created a simple GUIDE gui with a button and a static text field (set property value to be visible off). Then i put
set(handles.text1,'visible','on')
under the button callback.
Running this simple gui, i can turn the static text field to be visible when i push the button.
example of my test gui containing just a static text with tag text1 and a pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
status = get(handles.text1,'visible');
switch status
case 'on'
set(handles.text1,'visible','off');
case 'off'
set(handles.text1,'visible','on');
end
  4 Comments
Bryce
Bryce on 24 Jun 2014
I figured out what I did wrong, I was recalling the GUI and that reinitialized the visibility to off so as soon as it turned back on, it shut off. Sorry for wasting your time, thanks for the quick answer though
Joseph Cheng
Joseph Cheng on 24 Jun 2014
Edited: Joseph Cheng on 24 Jun 2014
Have you tried my simple example? I run it from both 2013b and 2011a. so i'm sure 2012b would work.
How are you getting to the static text callback? I didn't think static text has a Callback function. it has a create, delete, and buttondwn function.
how far deep is your set(handles.ErrorText...)? is it within the edit box? Also please differentiate between static text and edit text. Edit text box is what you can edit, static is just static text (user unable to input text)
check out my example. type in on, off, or anything you want.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!