Thread Subject:
Highlight Editable Text Field Upon Selection

Subject: Highlight Editable Text Field Upon Selection

From: Andrew

Date: 25 Jun, 2010 12:34:05

Message: 1 of 4

Hello all,

I was curious if anyone knew how set up an editable text field in such a way that whenever it was selected it would automatically highlight any text that was present in the field so that the user could simply begin typing in the new info. I attempted to use the 'ButtonDownFcn' to highlight the text whenever the user selected the field. However, this callback only works when the user clicked within a few pixels of the field but not when the user actually clicked inside the text field. If you have any ideas or suggestions it would be much appreciated. Thanks

Subject: Highlight Editable Text Field Upon Selection

From: Frédéric Bergeron

Date: 25 Jun, 2010 12:40:07

Message: 2 of 4

Hey,

Maybe you can try adding some html code in your code,,, simply type <html> at the beginning of a string command, like the string property of the uicontrol. But I don't know if there's a way in html for making what you want, it's just a suggestion.


"Andrew " <jtk1000@yahoo.com> wrote in message <i027nt$dkc$1@fred.mathworks.com>...
> Hello all,
>
> I was curious if anyone knew how set up an editable text field in such a way that whenever it was selected it would automatically highlight any text that was present in the field so that the user could simply begin typing in the new info. I attempted to use the 'ButtonDownFcn' to highlight the text whenever the user selected the field. However, this callback only works when the user clicked within a few pixels of the field but not when the user actually clicked inside the text field. If you have any ideas or suggestions it would be much appreciated. Thanks

Subject: Highlight Editable Text Field Upon Selection

From: Yair Altman

Date: 26 Jun, 2010 17:58:05

Message: 3 of 4

> I was curious if anyone knew how set up an editable text field in such a way that whenever it was selected it would automatically highlight any text that was present in the field so that the user could simply begin typing in the new info.


It's very easy with only a little bit of java magic powder:

1. First, download and install the FindJObj utility from the Matlab File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects

2. Next, do something like the following to get the editbox's Java reference:
  hEditbox = uicontrol('style','edit', ...);
  jEditbox = findjobj(hEditbox); % for single-line editboxes (max-min<=1)
  % for multi-line editboxes: jScrollbox = findjobj(hEditbox); jEditbox = jScrollbox.getViewport.getComponent(0);

3. Finally:
jEditbox.setSelectAllOnFocus(true);

Yair Altman
http://UndocumentedMatlab.com

Subject: Highlight Editable Text Field Upon Selection

From: Oleg Komarov

Date: 15 Dec, 2010 13:58:05

Message: 4 of 4

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <i05f3d$hpn$1@fred.mathworks.com>...
> > I was curious if anyone knew how set up an editable text field in such a way that whenever it was selected it would automatically highlight any text that was present in the field so that the user could simply begin typing in the new info.
>
>
> It's very easy with only a little bit of java magic powder:
>
> 1. First, download and install the FindJObj utility from the Matlab File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects
>
> 2. Next, do something like the following to get the editbox's Java reference:
> hEditbox = uicontrol('style','edit', ...);
> jEditbox = findjobj(hEditbox); % for single-line editboxes (max-min<=1)
> % for multi-line editboxes: jScrollbox = findjobj(hEditbox); jEditbox = jScrollbox.getViewport.getComponent(0);
>
> 3. Finally:
> jEditbox.setSelectAllOnFocus(true);
>
> Yair Altman
> http://UndocumentedMatlab.com

What if it doesn't work?

  hEditbox = uicontrol('style','edit', 'string','select me');
  jEditbox = findjobj(hEditbox);
  jEditbox.setSelectAllOnFocus(true)

I use R2010a, Vista32. New to GUIs.

Oleg

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
undocumented Yair Altman 26 Jun, 2010 13:59:21
java Yair Altman 26 Jun, 2010 13:59:21
gui Andrew 25 Jun, 2010 08:34:10
highlight Andrew 25 Jun, 2010 08:34:09
editable text Andrew 25 Jun, 2010 08:34:09
rssFeed for this Thread

Contact us