Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Jun. de 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.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by