How to limit the number of line entries in multiline editable textbox?
조회 수: 2 (최근 30일)
이전 댓글 표시
The gui (created via guide) has an edit text box and a multi-line editable text box. Through the edit text box, user supplies the number of entries to be made in the multi-line editable text box. The multi-line editable text box need to be configured to accept only those many entries.
This is my code:
set(handles.multilinetext,'Max',str2double(get(handles.edittext,'String')));
The multiline text box does accept multiple entries (for Max>=2 with Min being 0), but it does not limit the entries to the allowed. How to do it?
댓글 수: 0
채택된 답변
Walter Roberson
2017년 7월 15일
편집: Walter Roberson
2017년 7월 15일
There is no way at the MATLAB level to make this restriction, other than to check the number of lines after the user has entered them and take appropriate action. The choice at the MATLAB level is either 1 line (Max is 1) or any number of lines (Max > 1)
Possibly a restriction could be put on at the Java level.
You can create individual input lines in various was, but that level of control is not possible with uicontrol('style', 'edit')
댓글 수: 4
Walter Roberson
2017년 7월 16일
Taking another look at this question, I realized there is a way that is within pure MATLAB.
If you use the uicontrol KeyPressFcn callback on the uicontrol 'style', 'edit' then you can get at every key typed while it is being typed. You can then use your knowledge of the contents stored and your knowledge of the keys typed to decide whether to accept the keys or not.
Unfortunately, at least for all the HG1 based releases and possibly even now with HG2 (I have not checked), if you modify the String property during a KeyPressFcn callback, then subsequent KeyPressFcn callbacks will still retrieve the String property as if it had not been changed, and that will happen until the control loses focus (at which point the String property will get updated.) This oddity forces you to keep track of each key pressed yourself. (Note that relying on the KeyPressFcn to track key presses this way also requires that you handle deletions yourself, since the Backspace key should remove a character rather than adding a Backspace character.)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!