MATLAB Creating Graphical User Interfaces

(Barry) #1
UI for Setting Simulink Model Parameters


  • Closes the UI figure.


This is the Close button callback:


function CloseButton_Callback(hObject, eventdata, handles)
% Close the UI and any plot window that is open
if isfield(handles,'PlotFigure') && ...
ishandle(handles.PlotFigure),
close(handles.PlotFigure);
end
close(handles.F14ControllerEditor);


The List Box Callback and Create Function


This UI does not use the list box callback, but the push buttons reference the list
box in their callbacks (Simulate and store results, Remove, and Plot). GUIDE
automatically inserts an empty callback function when you add the list box to the layout.
It also sets the Callback property to execute this local function whenever users interact
with the list box.


You can delete the listbox callback function from the UI code and also delete the list box’s
Callback property value in the Property Inspector.


Set the Background to White


The list box create function enables you to determine the background color of the list box.
The following code shows the create function for the list box that is tagged ResultsList:


function ResultsList_CreateFcn(hObject, eventdata, handles)
% Hint: listbox controls usually have a white background, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(groot,'defaultUicontrolBackgroundColor'));
end

Free download pdf