From: Matt Fig on
Hello Per,

The reason I keep S.CUR is because the string of an editbox uicontrol does not update until the focus is taken away from the editbox or until it executes its callback. Thus if you create an editbox and in its keypressfcn you spit the string to the command line via get(H,'string'), you will get one of several outcomes.

Say you start typing the word: hank

1. If you just type the word without doing anything else, the string value will be empty every time. (ans = '' will show up 4 times.)
2. If you type the first two letters, then click outside the editbox, then click back into the editbox and type the last two, the string will show up as only the first two letters.
ans = ''
ans = ''
ans = ha
ans =ha
3. If you press return after every letter, and thus trigger the callback, then the string will lag one behind.
ans = ''
ans = h
ans = ha
ans = han


One way I have used to get around this is to use a JAVA robot in the keypressfcn to move the mouse to a location just outside of the editbox, click down and up, then move the pointer back to the right side editbox and click again to put the cursor at the end of the text. Of course this is kludgey, and is not without its own problems. I think the only way to get the full behavior of a JAVA type control is to use JAVA.


As for your code, I cannot run it. I think maybe my MATLAB version is too old. The only thing mentioned in my doc about the keyword classdef is that it is a new keyword.
From: per isakson on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <htjpul$je1$1(a)fred.mathworks.com>...
> Hello Per,
>
> The reason I keep S.CUR is because the string of an editbox uicontrol does not update until the focus is taken away from the editbox or until it executes its callback. Thus if you create an editbox and in its keypressfcn you spit the string to the command line via get(H,'string'), you will get one of several outcomes.
>
> Say you start typing the word: hank
>
> 1. If you just type the word without doing anything else, the string value will be empty every time. (ans = '' will show up 4 times.)
> 2. If you type the first two letters, then click outside the editbox, then click back into the editbox and type the last two, the string will show up as only the first two letters.
> ans = ''
> ans = ''
> ans = ha
> ans =ha
> 3. If you press return after every letter, and thus trigger the callback, then the string will lag one behind.
> ans = ''
> ans = h
> ans = ha
> ans = han
>
>
> One way I have used to get around this is to use a JAVA robot in the keypressfcn to move the mouse to a location just outside of the editbox, click down and up, then move the pointer back to the right side editbox and click again to put the cursor at the end of the text. Of course this is kludgey, and is not without its own problems. I think the only way to get the full behavior of a JAVA type control is to use JAVA.
>
>
> As for your code, I cannot run it. I think maybe my MATLAB version is too old. The only thing mentioned in my doc about the keyword classdef is that it is a new keyword.

Hello Matt,

Thank you for your detailed description of how Matlab behaves. It makes perfect sense, but it is not user friendly. My main problem was that I could not believe it when I saw it on the screen. And even now I cannot deduce that behavior from the documentation.

The breakpoint makes the editbox lose focus and, like magic, get(h,'String') returns what I expected. That is confusing to a naive users like me.

I had a go with Java, but run into problems trying to make it play with the layout manager. In my situation it takes too much time.

I'll make something simple and robust and blame Matlab if somebody complains regarding the lack of functionality.

Classdef is a new keyword and that together with a bunch of others make application development with Matlab a new game. I hope the next generation of handle graphic will be as good.

Matt, your GUII-examples are realy good. I have them in a separate folder, which I make the current folder when I need them to refresh my memory on how Matlab works. And I learned a few things. I have a 24" screen and can afford a wide current folder window. Long descriptive file-names would be helpful to me. And more comments on why you choose certain solutions are always welcome. An illustration of this behavior under KeypressFcn is well worth an example file. There is another thread today with another user that cannot believe his eyes.

Best regards
/ per