Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
multi-line editbox, slider set to bottom of editbox?

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 21 Sep, 2010 05:40:45

Message: 1 of 22

All,

What I have: a multi-line editbox. Max - Min > 1

Problem: The slider is set to be scrolled to the bottom, not to the top of the editbox

What I have tried: set(h_edit, 'Value',1)
This didn't work, so I tried to find the handle of the slider to set its value, but couldn't find its handle.
findobj('Style','slider') produced and empty array.
finall(gcf,'Style','slider') didn't find it either.

What I need: I think I need to find the slider's handle. Any ideas?

Thanks!

Sean

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 21 Sep, 2010 09:04:04

Message: 2 of 22

"Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i79ggt$88l$1@fred.mathworks.com>...
> All,
>
> What I have: a multi-line editbox. Max - Min > 1
>
> Problem: The slider is set to be scrolled to the bottom, not to the top of the editbox
>
> What I have tried: set(h_edit, 'Value',1)
> This didn't work, so I tried to find the handle of the slider to set its value, but couldn't find its handle.
> findobj('Style','slider') produced and empty array.
> finall(gcf,'Style','slider') didn't find it either.
>
> What I need: I think I need to find the slider's handle. Any ideas?
>
> Thanks!
>
> Sean

You don't need to look for the "hidden slider" of the listbox (you won't find it).
You must use the "ListboxTop" property of your listbox uicontrol.

ListboxTop indicates the index of the line displayed on the top of the uicontrol. By default, initial value is 1 (ie, the top most line displayed is the first line) but you can change this value to see line N at the top.

See following example :

h = uicontrol('style','listbox','String',cellstr(char(65:90)'), 'Position', [10, 10, 100, 100], 'Min', 0,'Max', 2,'Value', [])

set(h, 'ListboxTop', 10)

See Matlab help on UiControl Properties > ListboxTop for more details.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 21 Sep, 2010 14:58:05

Message: 3 of 22

Thomas,

Thank you for your quick response. Real quick: I am using this uicontrol to display results to the user, so I need my data displayed in a certain way. While I did get the listbox to work, the listbox does not support sprintf in the text and therefore my formatted data no longer looks professional. It there a way to do this using the uicontrol 'edit' as opposed to 'listbox'?

Sean



"Thomas Vanaret" <firstname.lastname@safran-engineering.com> wrote in message <i79se4$esf$1@fred.mathworks.com>...
> "Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i79ggt$88l$1@fred.mathworks.com>...
> > All,
> >
> > What I have: a multi-line editbox. Max - Min > 1
> >
> > Problem: The slider is set to be scrolled to the bottom, not to the top of the editbox
> >
> > What I have tried: set(h_edit, 'Value',1)
> > This didn't work, so I tried to find the handle of the slider to set its value, but couldn't find its handle.
> > findobj('Style','slider') produced and empty array.
> > finall(gcf,'Style','slider') didn't find it either.
> >
> > What I need: I think I need to find the slider's handle. Any ideas?
> >
> > Thanks!
> >
> > Sean
>
> You don't need to look for the "hidden slider" of the listbox (you won't find it).
> You must use the "ListboxTop" property of your listbox uicontrol.
>
> ListboxTop indicates the index of the line displayed on the top of the uicontrol. By default, initial value is 1 (ie, the top most line displayed is the first line) but you can change this value to see line N at the top.
>
> See following example :
>
> h = uicontrol('style','listbox','String',cellstr(char(65:90)'), 'Position', [10, 10, 100, 100], 'Min', 0,'Max', 2,'Value', [])
>
> set(h, 'ListboxTop', 10)
>
> See Matlab help on UiControl Properties > ListboxTop for more details.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 21 Sep, 2010 15:26:05

Message: 4 of 22

"Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i7ah5t$q7v$1@fred.mathworks.com>...
> Thomas,
>
> Thank you for your quick response. Real quick: I am using this uicontrol to display results to the user, so I need my data displayed in a certain way. While I did get the listbox to work, the listbox does not support sprintf in the text and therefore my formatted data no longer looks professional. It there a way to do this using the uicontrol 'edit' as opposed to 'listbox'?
>
> Sean
>

With Matlab 7.5 (R2007b), you can do the same as explained above with an "edit" UIControl instead of a "listbox". I think it was not possible with older version, since i didn't use it.

I prefer the "listbox" solution, but it doesn't support sprintf as you noticed it.
First split your text into lines as following :

txt = sprintf('This is a \nmulti-line \ntext\n')
lines = regexp(txt, '\n', 'split')

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 21 Sep, 2010 15:33:06

Message: 5 of 22

Correction :

It seems that ListboxTop doesn't work with "edit" UIControl.
So.. see above solution

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 21 Sep, 2010 16:26:21

Message: 6 of 22

Thomas,

Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.

So are you saying you don't think it can be done with a editbox in this version of MATLAB? I was a little confused on what the 'regexp' solution would do to set the slider to the top. Again, thanks for the help!

Sean

"Thomas Vanaret" <firstname.lastname@safran-engineering.com> wrote in message <i7aj7i$brq$1@fred.mathworks.com>...
> Correction :
>
> It seems that ListboxTop doesn't work with "edit" UIControl.
> So.. see above solution

Subject: multi-line editbox, slider set to bottom of editbox?

From: Yair Altman

Date: 21 Sep, 2010 16:40:26

Message: 7 of 22

"Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i79ggt$88l$1@fred.mathworks.com>...
> All,
>
> What I have: a multi-line editbox. Max - Min > 1
>
> Problem: The slider is set to be scrolled to the bottom, not to the top of the editbox


This is easy to do, using some undocumented magic:

http://UndocumentedMatlab.com/blog/setting-line-position-in-edit-box-uicontrol/
http://UndocumentedMatlab.com/blog/customizing-listbox-editbox-scrollbars/

Yair Altman
http://UndocumentedMatlab.com

Subject: multi-line editbox, slider set to bottom of editbox?

From: Walter Roberson

Date: 21 Sep, 2010 16:50:39

Message: 8 of 22

On 10-09-21 11:26 AM, Sean Blackman wrote:

> Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.
>
> So are you saying you don't think it can be done with a editbox in this
> version of MATLAB?

You could look at the solutions for this problem on undocumentedmatlab.com but
I would not _expect_ them to work on releases as old as R14.

There have been a lot of internal changes in the GUI since R14, and there
isn't a lot of profit in digging in to the old workings. (I'd be surprised if
Yair is making a profit on digging in to the current releases!)

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 21 Sep, 2010 17:08:04

Message: 9 of 22

Walter,

Yeah, I've tried a few of Yair's black-magic tricks, but nothing seems to work for R14. Bummer. I do like what he's doing though. Way over my head.

Any other ideas for how to set the scrollbar to the top for a multi-line editbox? Any ideas how how to get the slider's handle? I'm at a loss.

Sean


Walter Roberson <roberson@hushmail.com> wrote in message <i7antg$spm$1@canopus.cc.umanitoba.ca>...
> On 10-09-21 11:26 AM, Sean Blackman wrote:
>
> > Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.
> >
> > So are you saying you don't think it can be done with a editbox in this
> > version of MATLAB?
>
> You could look at the solutions for this problem on undocumentedmatlab.com but
> I would not _expect_ them to work on releases as old as R14.
>
> There have been a lot of internal changes in the GUI since R14, and there
> isn't a lot of profit in digging in to the old workings. (I'd be surprised if
> Yair is making a profit on digging in to the current releases!)

Subject: multi-line editbox, slider set to bottom of editbox?

From: Yair Altman

Date: 21 Sep, 2010 18:46:20

Message: 10 of 22

Walter Roberson <roberson@hushmail.com> wrote in message <i7antg$spm$1@canopus.cc.umanitoba.ca>...
> On 10-09-21 11:26 AM, Sean Blackman wrote:
>
> > Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.
> >
> > So are you saying you don't think it can be done with a editbox in this
> > version of MATLAB?
>
> You could look at the solutions for this problem on undocumentedmatlab.com but
> I would not _expect_ them to work on releases as old as R14.
>
> There have been a lot of internal changes in the GUI since R14, and there
> isn't a lot of profit in digging in to the old workings. (I'd be surprised if
> Yair is making a profit on digging in to the current releases!)


I wish I did make a profit (or even some reasonable income for that matter) from any of my work on undocumented stuff. As it turns out, almost all my work on undocumented features to date has been a Pro-Bono community service, and has not generated any significant income. I support myself by other means, including "regular" projects that use fully documented stuff and consulting non-Matlab projects.

I'm currently in the process of publishing a book on some undocumented aspects of Matlab. But the royalties from this book, even in the most optimistic scenario, will not nearly cover the countless hours I've worked on it.

Oh well... - all for the greater good...

Yair

Subject: multi-line editbox, slider set to bottom of editbox?

From: Jan Simon

Date: 21 Sep, 2010 20:08:04

Message: 11 of 22

Dear Yair,

thanks for helping us.
Your work increases the usability of Matlab and the fun of squeezing the system until it equals the programers wildest dreams.

Jan

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 22 Sep, 2010 10:32:06

Message: 12 of 22

"Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i7ambd$4gn$1@fred.mathworks.com>...
> Thomas,
>
> Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.
>
> So are you saying you don't think it can be done with a editbox in this version of MATLAB? I was a little confused on what the 'regexp' solution would do to set the slider to the top. Again, thanks for the help!
>
> Sean
>

@ Sean : You can use the "listbox" UIControl and then modify the "ListboxTop" vlaue as explained above.

The regexp is used only to split a multi-line text into a cell array composed of each lines. It's just a way to do it, other solutions are possible.
Once you have a cell array of strings, you can display it with the "listbox" UIControl.

Sorry if I have not been clear.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 27 Sep, 2010 04:23:04

Message: 13 of 22

Thomas,

Thanks for the reply again! Unfortunately the listbox will not be an option for me since I need formatted text and listbox does not support sprintf. I am still trying to find a way to do it with an editbox, and maybe I'll stumble upon something in the future.

I appreciate the replies though everyone.

Sean


"Thomas Vanaret" <firstname.lastname@safran-engineering.com> wrote in message <i7clv6$42o$1@fred.mathworks.com>...
> "Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i7ambd$4gn$1@fred.mathworks.com>...
> > Thomas,
> >
> > Yeah, I'm using MATLAB 7.0.0.27 (R14)... boo.
> >
> > So are you saying you don't think it can be done with a editbox in this version of MATLAB? I was a little confused on what the 'regexp' solution would do to set the slider to the top. Again, thanks for the help!
> >
> > Sean
> >
>
> @ Sean : You can use the "listbox" UIControl and then modify the "ListboxTop" vlaue as explained above.
>
> The regexp is used only to split a multi-line text into a cell array composed of each lines. It's just a way to do it, other solutions are possible.
> Once you have a cell array of strings, you can display it with the "listbox" UIControl.
>
> Sorry if I have not been clear.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Walter Roberson

Date: 27 Sep, 2010 13:46:47

Message: 14 of 22

On 26/09/10 11:23 PM, Sean Blackman wrote:
> Unfortunately the listbox will not be an
> option for me since I need formatted text and listbox does not support
> sprintf.

Someone wrote that about listbox last week, and I'm still at a loss to
understand what is meant.

uicontrol('Style','listbox','String', sprintf('Hello %s, this is visit
#%d', UserName, Visitnumber));


Listboxes can take cell arrays of strings, char arrays, and linear
strings with the parts separated by '|' . If you are trying to produce
multiple lines, sprintf() can certainly handle '|'

If your "formatting" replies upon lining up columns or things like that,
then the difficulty is not with sprintf and instead with the default
font being proportional spaced.

If your formatting relies upon tex or latex, sprintf can handle that.

If your formatting involves using HTML on some lines to add elements
such as color, there is no reason sprintf could not be involved with that.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 27 Sep, 2010 16:34:05

Message: 15 of 22

Walter,

Thanks for the reply. The formatting I am referring to is lining up columns of text. For instance, if I try to use ... 'String', sprintf('%s \t\t %.3f', 'x', 5.12345) ..., a listbox will ignore the '\t\t' portion.

> If your "formatting" replies upon lining up columns or things like that,
> then the difficulty is not with sprintf and instead with the default
> font being proportional spaced.

I am trying to display results to the user. There is a lot of data and it needs to be displayed in an organized way or it's just impossible to read.

Any ideas would be greatly appreciated!

Sean


Walter Roberson <roberson@hushmail.com> wrote in message <cf1oo.26327$wI.15310@newsfe11.iad>...
> On 26/09/10 11:23 PM, Sean Blackman wrote:
> > Unfortunately the listbox will not be an
> > option for me since I need formatted text and listbox does not support
> > sprintf.
>
> Someone wrote that about listbox last week, and I'm still at a loss to
> understand what is meant.
>
> uicontrol('Style','listbox','String', sprintf('Hello %s, this is visit
> #%d', UserName, Visitnumber));
>
>
> Listboxes can take cell arrays of strings, char arrays, and linear
> strings with the parts separated by '|' . If you are trying to produce
> multiple lines, sprintf() can certainly handle '|'
>
> If your "formatting" replies upon lining up columns or things like that,
> then the difficulty is not with sprintf and instead with the default
> font being proportional spaced.
>
> If your formatting relies upon tex or latex, sprintf can handle that.
>
> If your formatting involves using HTML on some lines to add elements
> such as color, there is no reason sprintf could not be involved with that.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Walter Roberson

Date: 27 Sep, 2010 18:35:08

Message: 16 of 22

On 10-09-27 11:34 AM, Sean Blackman wrote:

> Thanks for the reply. The formatting I am referring to is lining up
> columns of text. For instance, if I try to use ... 'String', sprintf('%s
> \t\t %.3f', 'x', 5.12345) ..., a listbox will ignore the '\t\t' portion.
>> If your "formatting" replies upon lining up columns or things like
>> that, then the difficulty is not with sprintf and instead with the
>> default font being proportional spaced.
>
> I am trying to display results to the user. There is a lot of data and
> it needs to be displayed in an organized way or it's just impossible to
> read.
>
> Any ideas would be greatly appreciated!

Use a monospaced font, and use fixed widths on all of your formatting items,
without any tabs. For example,

sprintf('%-3s %6.3f', 'x', 5.12345);

The %-3s would left-justify the 'x' within the 3 character field. The spaces
after that would be the equivalent of your \t . The %6.3f makes explicit how
many characters in total you expect for the %.3f field: there would be the
decimal point, 3 characters after the decimal (because of the .3
specification) and the total width would be 6, which would leave 2 characters
for the digits before the decimal point together with any sign.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 27 Sep, 2010 19:21:19

Message: 17 of 22

Walter,

... Somehow I feel I should have known that. Thank you! You have just saved me countless hours of trying to do it the hard way.

Sean


Walter Roberson <roberson@hushmail.com> wrote in message <i7qo9v$fu1$1@canopus.cc.umanitoba.ca>...
> On 10-09-27 11:34 AM, Sean Blackman wrote:
>
> > Thanks for the reply. The formatting I am referring to is lining up
> > columns of text. For instance, if I try to use ... 'String', sprintf('%s
> > \t\t %.3f', 'x', 5.12345) ..., a listbox will ignore the '\t\t' portion.
> >> If your "formatting" replies upon lining up columns or things like
> >> that, then the difficulty is not with sprintf and instead with the
> >> default font being proportional spaced.
> >
> > I am trying to display results to the user. There is a lot of data and
> > it needs to be displayed in an organized way or it's just impossible to
> > read.
> >
> > Any ideas would be greatly appreciated!
>
> Use a monospaced font, and use fixed widths on all of your formatting items,
> without any tabs. For example,
>
> sprintf('%-3s %6.3f', 'x', 5.12345);
>
> The %-3s would left-justify the 'x' within the 3 character field. The spaces
> after that would be the equivalent of your \t . The %6.3f makes explicit how
> many characters in total you expect for the %.3f field: there would be the
> decimal point, 3 characters after the decimal (because of the .3
> specification) and the total width would be 6, which would leave 2 characters
> for the digits before the decimal point together with any sign.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 30 Sep, 2010 04:04:19

Message: 18 of 22

For any interested: Listbox works great for displaying my data and being able to set the view to the top line.

Problem: I'm trying to set up my results in columns of text. Using sprintf('...', ......) with set field widths to accomplish this. However, lines with the EXACT same format are not lining up in columns correctly. There is an offset if the previous field is a string with different lengths. For instance:
%------------------------------------------------------------------------------
for i = 1:3
      sprintf('%-24s %-37s %-37.3f %-37s %-37s %10.4f',' ', Results.launch{2,i},
                Results.dv_loc(2,i), Results.dv_detail{1,i}, sporlp_str,Results.dv_loc(3,i) )
end
%------------------------------------------------------------------------------

yields:
%------------------------------------------------------------------------------
 Departure TOF #Revs Type OptVariable
JD 2453587.41 357.559 N = 0 --- 25.9881
JD 2453333.04 824.568 N = 1 Short Period 17.7533
JD 2453369.38 720.789 N = 1 Long Period 47.7669
%------------------------------------------------------------------------------

The last row is not lined up for some reason. It has something to do with the fact that the length of '---' and 'Short Period' are so different, but several different formats are producing the same problem. I have checked to make sure the 'OptVariable' column is all the same field width, and it is.

Why is the field width on the 'Type' column changing between rows? I have everything left aligned and all rows have the same field widths, so the last column should be aligned right?

Am I missing something here with listbox or sprintf?

Sean


"Sean Blackman" <sean.blackman@2007.usna.com> wrote in message <i7qqrf$fjp$1@fred.mathworks.com>...
> Walter,
>
> ... Somehow I feel I should have known that. Thank you! You have just saved me countless hours of trying to do it the hard way.
>
> Sean
>
>
> Walter Roberson <roberson@hushmail.com> wrote in message <i7qo9v$fu1$1@canopus.cc.umanitoba.ca>...
> > On 10-09-27 11:34 AM, Sean Blackman wrote:
> >
> > > Thanks for the reply. The formatting I am referring to is lining up
> > > columns of text. For instance, if I try to use ... 'String', sprintf('%s
> > > \t\t %.3f', 'x', 5.12345) ..., a listbox will ignore the '\t\t' portion.
> > >> If your "formatting" replies upon lining up columns or things like
> > >> that, then the difficulty is not with sprintf and instead with the
> > >> default font being proportional spaced.
> > >
> > > I am trying to display results to the user. There is a lot of data and
> > > it needs to be displayed in an organized way or it's just impossible to
> > > read.
> > >
> > > Any ideas would be greatly appreciated!
> >
> > Use a monospaced font, and use fixed widths on all of your formatting items,
> > without any tabs. For example,
> >
> > sprintf('%-3s %6.3f', 'x', 5.12345);
> >
> > The %-3s would left-justify the 'x' within the 3 character field. The spaces
> > after that would be the equivalent of your \t . The %6.3f makes explicit how
> > many characters in total you expect for the %.3f field: there would be the
> > decimal point, 3 characters after the decimal (because of the .3
> > specification) and the total width would be 6, which would leave 2 characters
> > for the digits before the decimal point together with any sign.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 1 Oct, 2010 07:54:07

Message: 19 of 22

Did you set the Uicontrol's "FontName" properties to "FixedWidth" ?
Default Font has not a fixed width, what may explain that your text looks different.

Check also that field width specified in sprintf is large enough.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Sean Blackman

Date: 5 Oct, 2010 02:48:06

Message: 20 of 22

Thomas,

It's official, you rock. Had no idea about 'FontName' property. Worked like a charm.

To all readers:
Setting UICONTROL property called 'FontName' to 'FixedWidth' will make formatting text a lot easier!

-Sean


"Thomas Vanaret" <firstname.lastname@safran-engineering.com> wrote in message <i8442v$8lb$1@fred.mathworks.com>...
> Did you set the Uicontrol's "FontName" properties to "FixedWidth" ?
> Default Font has not a fixed width, what may explain that your text looks different.
>
> Check also that field width specified in sprintf is large enough.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Walter Roberson

Date: 5 Oct, 2010 03:40:16

Message: 21 of 22

On 04/10/10 9:48 PM, Sean Blackman wrote:

> It's official, you rock. Had no idea about 'FontName' property. Worked
> like a charm.

On September 27th I told you twice to use a monospaced font. I assumed
you had done so after I'd told you twice, so I couldn't figure out why
your lines were not coming out properly.

Subject: multi-line editbox, slider set to bottom of editbox?

From: Thomas Vanaret

Date: 6 Oct, 2010 07:11:05

Message: 22 of 22

Walter Roberson <roberson@hushmail.com> wrote in message <A6xqo.16634$MQ1.6277@newsfe22.iad>...
> On 04/10/10 9:48 PM, Sean Blackman wrote:
>
> > It's official, you rock. Had no idea about 'FontName' property. Worked
> > like a charm.
>
> On September 27th I told you twice to use a monospaced font. I assumed
> you had done so after I'd told you twice, so I couldn't figure out why
> your lines were not coming out properly.

Walter indeed mentionned that point first, but thanks anyway.

When it doesn't work whereas it should, always suppose something has been forgotten on the way.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us