Creating Graphical User Interfaces Previous page   Next Page

Edit Text

To obtain the string a user typed in an edit box, get the String property in the callback.

For example, setting Max to 2, with the default value of 0 for Min, enables users to select multiple lines

Obtaining Numeric Data from an Edit Text Component

MATLAB returns the value of the edit text String property as a character string. If you want users to enter numeric values, you must convert the characters to numbers. You can do this using the str2double command, which converts strings to doubles. If the user enters nonnumeric characters, str2double returns NaN.

You can use the following code in the edit text callback. It gets the value of the String property and converts it to a double. It then checks whether the converted value is NaN (isnan), indicating the user entered a nonnumeric character and displays an error dialog (errordlg).

Triggering Callback Execution

For both UNIX and Windows, clicking on the menu bar of the figure window causes the edit text callback to execute. Clicking on other components or the background of the GUI also executes the callback.


Previous page  Check Boxes Sliders Next page

© 1994-2005 The MathWorks, Inc.