GUI issue, why does this happen?

Discussion in 'MATLAB' started by Jeremy Smith, Jul 30, 2007.

  1. Jeremy Smith

    Jeremy Smith Guest

    I have a GUI which generates and then waits for user inputs. It uses 'uiwait' and 'uiresume' to wait for user inputs. One of my edit fields has a KeyPressFcn defined for it which is suppose to get the string input in the edit field and then do a few things.

    The problem I've run across is that the KeyPressFcn does not see the string. If the user starts the GUI, clicks the field to give it focus, types something, and then presses the F1 (which triggers the function) the function cannot see the string typed.

    A workaround I've created changes the focus to another edit field, pauses, gets the string, and then returns focus to the original edit field.

    %% Original
    fname = get(h,'String'); % Function name

    %% Workaround
    uicontrol(edit_field2)
    pause(.01)
    fname = get(h,'String'); % Function name
    uicontrol(h)

    Why does this happen?
     
    Jeremy Smith, Jul 30, 2007
    #1
    1. Advertisements

  2. Jeremy Smith

    Joel Guest

    My guess...the string property on the edit box does not update until the editbox is executed. The execution occurs by whatever action executes a callback, even if no callback is defined. In the case of the edit box, this means either changing focus to another ui object, or hitting return.

    I think that this explains the "why". I think that what you are doing is the best workaround.
     
    Joel, Jul 30, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.