Clear Filters
Clear Filters

How to limit the number of line entries in multiline editable textbox?

2 views (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jul 2017
Edited: Walter Roberson on 15 Jul 2017
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 Comments
Thanigaivel Raja T
Thanigaivel Raja T on 16 Jul 2017
Thank you. The java code (in the link) requires major modification to suit my application (But I don't know java). I assume that this is recommended feature and I wish Yair Altman makes a java code for this too.
Further, I request if you can answer the following question too(which is continuation of this question):
Walter Roberson
Walter Roberson on 16 Jul 2017
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.)

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!