User_guide |

## 7.3: updateInterface

The second subfunction we will look at, `updateInterface`, uses the current selections to update the interface. This uses the structure "data" to update various parts of the interface. For this simple example this just means:

1. Update the selected item in the listbox

    set( gui.ListBox, 'Value', data.SelectedDemo );

2. Update the help button label

    demoName = data.DemoNames{ data.SelectedDemo };
    set( gui.HelpButton, 'String', ['Help for ',demoName] );

3. Update the view panel title

    set( gui.ViewPanel, 'Title', sprintf( 'Viewing: %s', demoName ) );

4. Update the ticked menu

    menus = get( gui.ViewMenu, 'Children' );
    set( menus, 'Checked', 'off' );
    % Use the name to work out which menu item should be ticked
    whichMenu = strcmpi( demoName, get( menus, 'Label' ) );
    set( menus(whichMenu), 'Checked', 'on' );

In general, this update function is called whenever the underlying shared "data" structure is changed. This happens when the user clicks a button, selects a list item or a menu. Next we will look at a typical callback.

(Full source code for this application is available here: [ view | edit | run ] )

© 2024 The MathWorks Ltd `•` Terms of Use `•` Patents `•` Trademarks