Thread Subject: Locate position of cursor in edit object in GUI

Subject: Locate position of cursor in edit object in GUI

From: Jesse Lai

Date: 24 Apr, 2008 03:02:23

Message: 1 of 4

Is there a way to detect the position of the cursor in an edit box in a
GUI? I have a couple of different use cases where this would be useful.

The one I'd like to get working is a more elegant password entry box
similar to the ones on the file exchange. The problem with those ones
is that they don't let you cursor over to use backspace on anything
other than the last character, which may be problematic for users who
are used to being able to do this.

Thanks,

Jesse

Subject: Locate position of cursor in edit object in GUI

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 24 Apr, 2008 17:17:51

Message: 2 of 4

In article <oLCdnV7AEt4bapLVnZ2dnUVZ_oOnnZ2d@comcast.com>,
Jesse Lai <"jlai.[DELETETHIS]matlab"@gmail[NOSPAM].moc> wrote:
>Is there a way to detect the position of the cursor in an edit box in a
>GUI? I have a couple of different use cases where this would be useful.

Only by going in at the Java level.
--
  "Do not wait for leaders. Do it alone, person to person."
                                              -- Mother Teresa

Subject: Locate position of cursor in edit object in GUI

From: Jesse Lai

Date: 25 Apr, 2008 05:06:16

Message: 3 of 4

Walter Roberson wrote:
> In article <oLCdnV7AEt4bapLVnZ2dnUVZ_oOnnZ2d@comcast.com>,
> Jesse Lai <"jlai.[DELETETHIS]matlab"@gmail[NOSPAM].moc> wrote:
>> Is there a way to detect the position of the cursor in an edit box in a
>> GUI? I have a couple of different use cases where this would be useful.
>
> Only by going in at the Java level.

I thought that might be the case. I believe that I have found the way
using Java as Walter suggested. If you have the handle to the edit box
(e.g. hEdit), then I used Yair Altman's findjobj to get the java handle as

jEdit = findjobj(hEdit);

Then you can use:

get(jEdit, 'SelectionStart')
get(jEdit, 'SelectionEnd')

or the equivalent set methods.

Is there a better way to get the java handle directly without using this
other function?

Thanks,

Jesse

Subject: Locate position of cursor in edit object in GUI

From: Michelle

Date: 5 Jun, 2008 15:12:03

Message: 4 of 4

Jesse Lai <"jlai.[DELETETHIS]matlab"@gmail[NOSPAM].moc>
wrote in message
<vYadnZaxFL2X-4zVnZ2dnUVZ_s2tnZ2d@comcast.com>...
> Walter Roberson wrote:
> > In article <oLCdnV7AEt4bapLVnZ2dnUVZ_oOnnZ2d@comcast.com>,
> > Jesse Lai <"jlai.[DELETETHIS]matlab"@gmail[NOSPAM].moc>
wrote:
> >> Is there a way to detect the position of the cursor in
an edit box in a
> >> GUI? I have a couple of different use cases where this
would be useful.
> >
> > Only by going in at the Java level.
>
> I thought that might be the case. I believe that I have
found the way
> using Java as Walter suggested. If you have the handle to
the edit box
> (e.g. hEdit), then I used Yair Altman's findjobj to get
the java handle as
>
> jEdit = findjobj(hEdit);
>
> Then you can use:
>
> get(jEdit, 'SelectionStart')
> get(jEdit, 'SelectionEnd')
>
> or the equivalent set methods.
>
> Is there a better way to get the java handle directly
without using this
> other function?
>
> Thanks,
>
> Jesse

Hi Jesse,

It sounds like I am attempting a similar task in my MATLAB
GUI. I have an edit uicontrol where I allow the user in
type in a password. I handle each key press with the edit
uicontrol's 'KeyPressFcn'. As characters are typed in, I
replace the characters with asterisks and set the string of
asterisks to the edit uicontrol. If a backspace is pressed,
I delete the last character of the string. BUT, what if the
user uses the mouse to highlight all or some of the string,
then hits backspace? They will expect the entire
highlighted portion of the string to be deleted, right?

So grabbing the Java object and checking the
'SelectionStart' and 'SelectionEnd' properties definitely
seems like a potential solution. But these properties do
not seem to be properly set. 'SelectionStart' and
'SelectionEnd' always return equivalent values. Have you
encountered this?

Thanks,

Michelle Kline

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
cursor position Michelle 5 Jun, 2008 11:15:08
java object Michelle 5 Jun, 2008 11:15:08
edit object Michelle 5 Jun, 2008 11:15:08
selected Michelle 5 Jun, 2008 11:15:08
rssFeed for this Thread

Contact us at files@mathworks.com