User guide previous pagenext page

3.1: Enable example Go back up one level

(The code for this example can be found here: [ view | edit | run ] )

This example shows how the enable property can be used to indicate to users which bits of an interface are currently relevant. This is particularly useful for preventing unwanted clicking during long calculations, loading and saving!

Open a window and add a panel
fig = figure( 'Name', 'Enable example', ...
    'Position', [100 100 150 250], ...
    'MenuBar', 'none', ...
    'ToolBar', 'none', ...
    'NumberTitle', 'off' );
panel = uiextras.BoxPanel( 'Parent', fig, 'Title', 'Panel' );

Put some buttons inside the panel
box = uiextras.VButtonBox( 'Parent', panel );
uicontrol( 'Parent', box, 'String', 'Button 1' );
uicontrol( 'Parent', box, 'String', 'Button 2' );
uicontrol( 'Parent', box, 'String', 'Button 3', 'Enable', 'off' );
uicontrol( 'Parent', box, 'String', 'Button 4' );
uicontrol( 'Parent', box, 'String', 'Button 5', 'Enable', 'off' );
uicontrol( 'Parent', box, 'String', 'Button 6' );

Try disabling the panel
set( panel, 'Enable', 'off' );

Try enabling the panel. Note that the original "enable" state of each button is remembered.
set( panel, 'Enable', 'on' );


© 2014 The MathWorks Ltd Terms of Use Patents Trademarks