Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scrolling in GUI static text boxes?

886 views
Skip to first unread message

alayi

unread,
May 22, 2007, 4:26:43 PM5/22/07
to
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.

Walter Roberson

unread,
May 22, 2007, 4:30:36 PM5/22/07
to
In article <ef57c...@webcrossing.raydaftYaTP>,

alayi <alayi_126@[NOSPAM]yahoo.com> 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.

No way is provided, unless it is one of the hidden java methods.


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

This happens to be -exactly- what I'm coding right now.

I suspect someone has already done the work and put it up on the
File Exchange (FEX). (I didn't look there myself for copyright
reasons.)
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer

Matt Whitaker

unread,
May 22, 2007, 4:47:38 PM5/22/07
to
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)

Yair Altman

unread,
May 23, 2007, 2:24:46 PM5/23/07
to
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

Gaillot Arnaud

unread,
Mar 6, 2008, 9:54:02 AM3/6/08
to
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.

Gaillot Arnaud

unread,
Mar 6, 2008, 9:55:03 AM3/6/08
to

Ehsan na

unread,
Sep 27, 2011, 5:12:28 PM9/27/11
to
"Yair Altman" wrote in message <ef57...@webcrossing.raydaftYaTP>...
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

Yair Altman

unread,
Sep 28, 2011, 10:07:26 AM9/28/11
to
"Ehsan na" wrote in message <j5te7s$p33$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

Ehsan na

unread,
Sep 29, 2011, 9:30:30 AM9/29/11
to
"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

Yair Altman

unread,
Oct 1, 2011, 1:13:13 PM10/1/11
to
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
0 new messages