Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 21 Giu 2017
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.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by