Specifications
1 Getting Started with GUIDE
1-24
Example – Programming the Menu Callbacks
After adding the File menu to the layout (you cannot see the menu bar in the
Layout Editor), edit the application M-file. It will contain empty callback
functions for the
File menu as well as the Print and Close items.
File Menu Callback
By default, when a user clicks on the File menu, MATLAB displays the menu
items. Therefore, the only purpose of the
File menu callback in this example is
to disable the
Print menu item when there is no plot being displayed. You can
accomplish this by checking to see if the axes
Children property is empty (in
which case, there is nothing displayed in the axes).
The menu’s
Enable property controls whether a particular item is active or
inactive. The item is grayed out if
Enable is set to off.
The callback uses
isempty to determine if the axes contains a plot and enables
or disables the menu accordingly.
function varargout = file_menu_Callback(h, eventdata, handles, varargin)
if isempty(get(handles.axes1,'Children'))
set(handles.print_submenu,'Enable','off')