Specifications
Programming Callbacks for GUI Components
4-11
You can use the following code in the edit text callback. It gets the value of the
String property and converts it to a double. It then checks whether the
converted value is
NaN (isnan), indicating the user entered a nonnumeric
character and displays an error dialog (
errordlg).
function edittext1_Callback(hObject, eventdata, handles)
user_entry = str2double(get(hObject,'string'));
if isnan(user_entry)
errordlg('You must enter a numeric value','Bad Input','modal')
end
% proceed with callback...
Triggering Callback Execution
For both UNIX and Windows, clicking on the menu bar of the figure window
causes the edit text callback to execute. Clicking on other components or the
background of the GUI also executes the callback.
Sliders
You can determine the current value of a slider from within its callback by
querying its
Value property, as illustrated in the following example:
function slider1_Callback(hObject, eventdata, handles)
slider_value = get(hObject,'Value');
% proceed with callback...
The Max and Min properties specify the slider’s range (Max - Min).
List Boxes
Triggering Callback Execution
MATLAB evaluates the list box’s callback after the mouse button is released or
after certain key press events.
• The arrow keys change the
Value property and trigger callback execution.
•
Enter and Space do not change the Value property but trigger callback
execution.
If the user double-clicks, the callback executes after each click. MATLAB sets
Selection Type to normal on the first click and to open on the second click. The