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:
scrolling in GUI static text boxes?

Subject: scrolling in GUI static text boxes?

From: alayi

Date: 22 May, 2007 16:26:43

Message: 1 of 9

Is it possible to allow scrollbars in static text boxes or are
scrollbars only for editable text? I have not found a way to enable
this for static text.

I would like multiple lines of text with a scrollbar that are not
selectable or editable.

Thanks.

Subject: scrolling in GUI static text boxes?

From: Matt Whitaker

Date: 22 May, 2007 16:47:38

Message: 2 of 9

Your best bet is to use an edit box with its 'Enable' property set to
inactive. It will behave similar to a static text box. For example:
s = num2str((1:1000)');
h = figure;
uicontrol('Parent',h,...
          'Units','normalized',...
          'Position',[0.1,0.1,0.8,0.8],...
          'Style','edit',...
          'Max',100,...
          'Enable','inactive',...
          'String',s)

 alayi wrote:
>
>
> Is it possible to allow scrollbars in static text boxes or are
> scrollbars only for editable text? I have not found a way to enable
> this for static text.
>
> I would like multiple lines of text with a scrollbar that are not
> selectable or editable.
>
> Thanks.

Subject: scrolling in GUI static text boxes?

From: Yair Altman

Date: 23 May, 2007 14:24:46

Message: 3 of 9

Small addendum to Matt's correct answer:

If you want a *SELECTABLE* but *NON-EDITABLE* multi-line editbox, you
can't use Matlab's 'enable'='off' property, since the editbox will
not be selectable in this case. You have 2 options:

1. Creata a javax.swing.JTextPane or JTextArea object and place it
on-screen using javacomponent or uicomponent (from the File
Exchange). Then clear the object's Editable property while keeping
the Enabled property set. Here's a link describing the different
possible editboxes you can use:

 <http://java.sun.com/docs/books/tutorial/uiswing/components/text.html>

2. Use findjobj from the File Exchange to clear Matlab's standard
editbox Editable property. This property is hidden in Matlab and
available only if you directly access the underlying Java object
(which is a JTextPane-inherited object, by the way). Here's how:

hEdit=uicontrol('style','edit','max',100,'enable','on',...);
jEdit=findjobj(hEdit,'nomenu'); %get the UIScrollPane container
jEdit=jEdit.getComponent(0).getComponent(0);
set(jEdit,'Editable',0);

BTW, you can use both these options to set other properties that are
unavailable in Matlab's standard uicontrol: CaretColor,
CaretPosition, DisabledTextColor etc.

Yair Altman

Subject: scrolling in GUI static text boxes?

From: Gaillot Arnaud

Date: 6 Mar, 2008 14:54:02

Message: 4 of 9

Hi,

Is there a way to hide lateral scroll bar on multi-Line edit
boxes when scrolling is not needed ?

I tried to access and modify java graphic attributes trough
findjobj.m, but did not find those corresponding to scrolling.

Subject: scrolling in GUI static text boxes?

From: Gaillot Arnaud

Date: 6 Mar, 2008 14:55:03

Message: 5 of 9

Hi,

Is there a way to hide lateral scroll bar on multi-Line edit
boxes when scrolling is not needed ?

I tried to access and modify java graphic attributes trough
findjobj.m, but did not find those corresponding to scrolling.

Subject: scrolling in GUI static text boxes?

From: Ehsan na

Date: 27 Sep, 2011 21:12:28

Message: 6 of 9

"Yair Altman" wrote in message <ef57c47.1@webcrossing.raydaftYaTP>...
> Small addendum to Matt's correct answer:
>
> If you want a *SELECTABLE* but *NON-EDITABLE* multi-line editbox, you
> can't use Matlab's 'enable'='off' property, since the editbox will
> not be selectable in this case. You have 2 options:
>
> 1. Creata a javax.swing.JTextPane or JTextArea object and place it
> on-screen using javacomponent or uicomponent (from the File
> Exchange). Then clear the object's Editable property while keeping
> the Enabled property set. Here's a link describing the different
> possible editboxes you can use:
>
> <http://java.sun.com/docs/books/tutorial/uiswing/components/text.html>
>
> 2. Use findjobj from the File Exchange to clear Matlab's standard
> editbox Editable property. This property is hidden in Matlab and
> available only if you directly access the underlying Java object
> (which is a JTextPane-inherited object, by the way). Here's how:
>
> hEdit=uicontrol('style','edit','max',100,'enable','on',...);
> jEdit=findjobj(hEdit,'nomenu'); %get the UIScrollPane container
> jEdit=jEdit.getComponent(0).getComponent(0);
> set(jEdit,'Editable',0);
>
> BTW, you can use both these options to set other properties that are
> unavailable in Matlab's standard uicontrol: CaretColor,
> CaretPosition, DisabledTextColor etc.
>
> Yair Altman


I had a similar problem, and thanks to Yair's, this findjobj can solve the problem.

Still, I have another issue;
I use GUIDE to create my objects (in this case edit box). So, I put Yair's snippet in my editbox_CreateFcn(). But findjobj(hObject,'nomenu') returns nothing !

I also tried putting this snippet under figure_OpeningFcn() but still the findjobj(handles.editbox,'nomenu') returns nothing.

Finally I created a editbox_KeyPressFcn() and put the code there. and it works there! But it is a clumsy solution. The user needs to press a key on the box before it turns to be uneditable!
I think this issue has something to do with the way objects are created in GUIDE.

Any idea how to make the code work automatically without intervention of the user?

Thanks in advance

Subject: scrolling in GUI static text boxes?

From: Yair Altman

Date: 28 Sep, 2011 14:07:26

Message: 7 of 9

"Ehsan na" wrote in message <j5te7s$p33$1@newscl01ah.mathworks.com>...
> "Yair Altman" wrote in message <ef57c47.1@webcrossing.raydaftYaTP>...
> > Small addendum to Matt's correct answer:
> >
> > If you want a *SELECTABLE* but *NON-EDITABLE* multi-line editbox, you
> > can't use Matlab's 'enable'='off' property, since the editbox will
> > not be selectable in this case. You have 2 options:
> >
> > 1. Creata a javax.swing.JTextPane or JTextArea object and place it
> > on-screen using javacomponent or uicomponent (from the File
> > Exchange). Then clear the object's Editable property while keeping
> > the Enabled property set. Here's a link describing the different
> > possible editboxes you can use:
> >
> > <http://java.sun.com/docs/books/tutorial/uiswing/components/text.html>
> >
> > 2. Use findjobj from the File Exchange to clear Matlab's standard
> > editbox Editable property. This property is hidden in Matlab and
> > available only if you directly access the underlying Java object
> > (which is a JTextPane-inherited object, by the way). Here's how:
> >
> > hEdit=uicontrol('style','edit','max',100,'enable','on',...);
> > jEdit=findjobj(hEdit,'nomenu'); %get the UIScrollPane container
> > jEdit=jEdit.getComponent(0).getComponent(0);
> > set(jEdit,'Editable',0);
> >
> > BTW, you can use both these options to set other properties that are
> > unavailable in Matlab's standard uicontrol: CaretColor,
> > CaretPosition, DisabledTextColor etc.
> >
> > Yair Altman
>
>
> I had a similar problem, and thanks to Yair's, this findjobj can solve the problem.
>
> Still, I have another issue;
> I use GUIDE to create my objects (in this case edit box). So, I put Yair's snippet in my editbox_CreateFcn(). But findjobj(hObject,'nomenu') returns nothing !
>
> I also tried putting this snippet under figure_OpeningFcn() but still the findjobj(handles.editbox,'nomenu') returns nothing.
>
> Finally I created a editbox_KeyPressFcn() and put the code there. and it works there! But it is a clumsy solution. The user needs to press a key on the box before it turns to be uneditable!
> I think this issue has something to do with the way objects are created in GUIDE.
>
> Any idea how to make the code work automatically without intervention of the user?
>
> Thanks in advance


You can't use findjobj in the createFcn or OpeningFcn because the Java peer objects are still not created at this time. Instead, place findjobj in the OutputFcn. See http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/#comment-6045

Yair Altman
http://UndocumentedMatlab.com

Subject: scrolling in GUI static text boxes?

From: Ehsan na

Date: 29 Sep, 2011 13:30:30

Message: 8 of 9

"Yair Altman" wrote in message <j5v9mu$lf5$1@newscl01ah.mathworks.com>...
>
>
> You can't use findjobj in the createFcn or OpeningFcn because the Java peer objects are still not created at this time. Instead, place findjobj in the OutputFcn. See http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/#comment-6045
>
> Yair Altman
> http://UndocumentedMatlab.com

Yea, I figured it out the hard way! after trying many different functions, and ways, (keypress, mouse motion, button down,...). I wish I had read that comment earlier :p
For this matter, I also tried to find a function to force matlab to refresh the figure (as if it re-draws the objects, apply all changes made to them and empty the buffer), but no luck.

Maybe you can explain why this happens with findjobj, which I think it should not be like this;
I set the vertical scroll bar of edit box to AS NEEDED and Editable to off in outputFcn.

jEditObj = findjobj(handles.editbox,'nomenu');
set(jEditObj,'VerticalScrollBarPolicy',20);
jEdit = jEditObj.getComponent(0).getComponent(0);
set(jEdit,'Editable','off');

in this stage jEditObj is: javahandle_withcallbacks.com.mathworks.hg.peer.utils.UIScrollPane

later in my program I try to change 'Editable' property of this object:

jEditObj = findjobj(handles.editbox,'nomenu');
jEdit = jEditObj.getComponent(0).getComponent(0);
set(jEdit, 'Editable', 'on');

it does not work, because jEditObj is: javahandle_withcallbacks.com.mathworks.hg.peer.EditTextPeer$hgTextEditMultiline

It has something to do with the scroll bar, since it only happens while there is not much text in the text box and hence scroll bar is not active. In this time I cannot even set the scroll bar active once I already deactivated it, because the object that findjobj(handles.editbox) returns doesn't have 'Vertical ScrollBarPolicy' property anymore. When the scroll bar gets visible again it is solved.

Is it the way it should be? I don't expect the findjobj returns different java class names for a given GUI object, when I change a property of that object. I know I can use jEditObj.getParent.getParent to have access to those properties again, but it does not seem a systematic way to use getParent sometimes and getComponent some other times. Maybe I am missing something here, your description will be appreciated.

To bypass the problem, right now I save the jEditObj in the first time I recall it, in appdata and through the program I use that one.

Regards

Subject: scrolling in GUI static text boxes?

From: Yair Altman

Date: 1 Oct, 2011 17:13:13

Message: 9 of 9

editboxes use a different object for single-line and multi-line editboxes. This depends on the Max-Min properties. Only the multi-line object uses scrollbars, the single-line does not. This could be the reason that sometimes findjobj gets the editbox object directly, and sometimes only its container scrollpane.

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

No tags are associated with 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