How I set a string in edit field when string is longer than the field itself

6 views (last 30 days)
Hi guys,
I have an idea how I want it to behave but I have no clue how to do it. So I beg for help :)
I have edit field with for exaple max. 15 char...and I have char with for example 26 char and when i put it there I want to bw shown in edit field the end of the string and to sign that some of the text is missing I want there to be '...'
In example it will be better:
edit field 15char: xxxxxxxxxxxxxxx
string 26 char: abcdefgh...xyz
and when I put the sting in the field I want it to be shown like: ...opqrstuvwxyz
Thanks for replies...Peter
  4 Comments
Walter Roberson
Walter Roberson on 5 Nov 2012
You can set the KeyPressFunction callback in a uicontrol() of style 'edit' and so it is possible to do as the user types.
Petr
Petr on 5 Nov 2012
I dont need it to be interactive...showing after setting the field string is OK...
To be specific...I am setting in the edit field a path to chosen file by uigetfile...

Sign in to comment.

Accepted Answer

per isakson
per isakson on 5 Nov 2012
I assume you refer to an uicontrol of style: edit, text or listbox.
Idea: store the full string in UserData and truncate before you set the property, String, of the uicontrol.
  2 Comments
Petr
Petr on 6 Nov 2012
Edited: Petr on 6 Nov 2012
Thanks, I also thought about it like that...but...isnt there a much more elegant way ?
Walter Roberson
Walter Roberson on 6 Nov 2012
No there isn't. It might be possible using Java controls, but getting access to those controls is not elegant.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 5 Nov 2012
There is no setting you can make at the MATLAB level to cause the uicontrol displayed string to have the ellipses and yet for the control's String property to have the full contents. I do not know if it could be done at the Java level.
You can set() the String property to display any given string, including a literal '...' but that contents will be what is retrieved when you get() the String property.

Categories

Find more on Migrate GUIDE Apps 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!