GUI the time set function works

2 ビュー (過去 30 日間)
Zhichao Wang
Zhichao Wang 2015 年 8 月 6 日
コメント済み: Walter Roberson 2015 年 8 月 6 日
A beginner just learning matlab gui. I'd like to change the string of an edit box when an key pressed to make the input to be numeric. And when testing this, I found I had to press Enter to make this set function work. And after commenting the set function, other works as expected. This is the code below.
function edit1_KeyPressFcn(hObject, eventdata, handles)
if ~ismember(eventdata.Key,'1234567890.')
origin = get(handles.edit1, 'string');
disp('error')
set(handles.edit1, 'string', origin(1:end-1));
else
disp('normal')
end
Each time I entered a number, it can show 'normal' each time. But when entering not a number, it just showed 'error' without setting the string until I pressed an 'Enter' to make it work. I'd like to know the time set function works in this case

回答 (1 件)

Zhichao Wang
Zhichao Wang 2015 年 8 月 6 日
I have already found that the string property does not update as you type in an edit box. Therefore, is there any way I can make string property update each I press a key?
  1 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 6 日
No, not without going to the Java level.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by