How to move cursor line within edit box of uicontrol?
조회 수: 4(최근 30일)
표시 이전 댓글
Dominik Mattioli 2018년 8월 15일
답변: Walter Roberson 2018년 8월 15일
I've a string that isn't always viewable within my edit box. I'd like to be able to move the cursor and/or adjust the view of the edit box so that the user can see the end of the string.
myFig = figure;
myEdit = uicontrol(myFig,'style','edit',...
'string','a string that is way too long to see for this edit box',...
'position',[.45 .45 .25 .1],...
From this example, you cannot edit the text but you also cannot highlight the text to scroll horizontally and can only see part of the string. Is there a callback function that can be created to solve this?
Walter Roberson 2018년 8월 15일
Your best choice is probably to work at the Java level, taking advantage of some of the information about uicontrol that you can find at http://undocumentedmatlab.com
If you want to stay within MATLAB without taking advantage of the underlying Java, then the way to handle this is to create a uicontrol that is as wide as the largest string you might ever need. Then put that uicontrol inside a uipanel ("inner panel") that is slightly wider still. Then put that inner panel inside of another uipanel ("outer panel") that is the width of the screen area you want to display into, with the outer panel set to clip. Now, arrange your scrolling so that what the scrolling does is set the Position of the inner uipanel relative to the outer uipanel. This is like having a fixed area of clear glass that you are moving a book under.
I do not recommend putting the uicontrol directly inside just one uipanel and then setting the Position of the uicontrol to accomplish the scrolling. Although that would seem to accomplish the same effect, changing the Position of a uicontrol is high overhead because it makes the uicontrol recalculate the drawing of the string. I also have found other problems with using only a single uipanel like that, but I do not recall what they are at the moment.
Notice with this second approach, you never try to change the uicontrol itself -- never try to scroll it for example. The control you have over scrolling a uicontrol at the MATLAB level is pretty weak, unfortunately.
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!