フィルターのクリア

How to make text in uicontrol object disappear when user starts typing?

1 回表示 (過去 30 日間)
KAE
KAE 2017 年 6 月 21 日
コメント済み: KAE 2017 年 6 月 27 日
I have a question about the following editable text box,
f = figure; % Make example figure
peaks; % Plot peaks data that comes preloaded with Matlab
S.ed = uicontrol('style','edit',... % Make editable text box
'units','pixels', ...
'position',[10 100 200 30],...
'fontsize',11,...
'string','Enter a Word');
How do I implement the following?
  1. When the user starts to type, the text 'Enter a Word' disappears from the text box
  2. When the user presses enter at the end of a character sequence, the entry is "done" and no more characters are accepted, similar to a carriage return?
As a user, this is how I expect text boxes to work, but I don't know how to implement it.

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 21 日
In order to do that, you have to implement a KeyPressedFcn callback for the uicontrol, and you have to manage all of the text yourself, including deletions. This gets trickier because when you are in a KeyPressedFcn callback for a text box, as you set() the String property, the display will not be updated (unless they changed that in R2014b and later), so you have to keep track of all of the text yourself.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by