필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by