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:
Matlab GUI static text

Subject: Matlab GUI static text

From: trancemissionxxi@gmail.com

Date: 24 Jan, 2009 02:37:14

Message: 1 of 16

Hello,

I have a question related to GUI development. I would like to have a
text in the GUI that is selectable but cannot be changed.

If I use 'text', then the string is not selectable by mouse. If I use
'edit' then the text is selectable but can also be changed.

Is there any property I can set to make the text selectable but not
changeable (in 'text' or 'edit' styles)?

Thank you!

Subject: Matlab GUI static text

From: Matt Fig

Date: 24 Jan, 2009 03:04:04

Message: 2 of 16

I am curious, why do you need selectable text that is not editable? Do you mean you want to be able to copy and paste the text?





[_qU`^S[UTxaq]7 2faWSa,g^qaWWqfhTbqkxWZqZYa?SaKbSqgf`qSSS_Z

Subject: Matlab GUI static text

From: trancemissionxxi@gmail.com

Date: 24 Jan, 2009 03:06:52

Message: 3 of 16

On Jan 23, 7:04=A0pm, "Matt Fig" <spama...@yahoo.com> wrote:
> I am curious, why do you need selectable text that is not editable? =A0Do=
 you mean you want to be able to copy and paste the text?
>
> [_qU`^S[UTxaq]7 2faWSa,g^qaWWqfhTbqkxWZqZYa?SaKbSqgf`qSSS_Z

Yes, I would like to be able to select and copy the text, but not
delete it by accident if editable.

Thanks.

Subject: Matlab GUI static text

From: Matt Fig

Date: 24 Jan, 2009 03:15:05

Message: 4 of 16

You could do something like this, but I really think there must be a better way to do what you want.



tx = uicontrol('sty','ed','str','toomany','call','set(gcbo,''string'',''toomany'')')



Now this the text can be highlighted, but if changed it will change right back when return is hit or another uicontrol is selected.




iYRYKU^^YKipp*KKLK7`YOKM^ii/Qi$XX_YRSiwWOSOY_CZiKcVRLiMWZOV

Subject: Matlab GUI static text

From: trancemissionxxi@gmail.com

Date: 24 Jan, 2009 03:32:13

Message: 5 of 16

On Jan 23, 7:15=A0pm, "Matt Fig" <spama...@yahoo.com> wrote:
> You could do something like this, but I really think there must be a bett=
er way to do what you want. =A0
>
> tx =3D uicontrol('sty','ed','str','toomany','call','set(gcbo,''string'','=
'toomany'')')
>
> Now this the text can be highlighted, but if changed it will change right=
 back when return is hit or another uicontrol is selected.
>
> iYRYKU^^YKipp*KKLK7`YOKM^ii/Qi$XX_YRSiwWOSOY_CZiKcVRLiMWZOV

It does the trick. Thank you. Should have thought of that.

Subject: Matlab GUI static text

From: Walter Roberson

Date: 24 Jan, 2009 04:15:56

Message: 6 of 16

Matt Fig wrote:
> You could do something like this, but I really think there must be a better way to do what you want.

> tx = uicontrol('sty','ed','str','toomany','call','set(gcbo,''string'',''toomany'')')

> Now this the text can be highlighted, but if changed it will change right back when return
> is hit or another uicontrol is selected.

However, there is a well-known limitation with edit boxes, that if you are editing
and then you click on the figure instead of pressing return or on another uicontrol,
then the callback will not be called but the changed text will still be shown.

In order to do what the original poster wants without this possibility, the original
poster will (according to what I have read) work at the java level, probably by
starting with a uicontrol and modifying the methods that that particular control
uses. I believe the relevant code had been shown in the past; if I were to search
for it, I would start by examining Yair Altman's old postings.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Matlab GUI static text

From: trancemissionxxi@gmail.com

Date: 24 Jan, 2009 06:28:06

Message: 7 of 16

On Jan 23, 8:15=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
> Matt Fig wrote:
> > You could do something like this, but I really think there must be a be=
tter way to do what you want. =A0
> > tx =3D uicontrol('sty','ed','str','toomany','call','set(gcbo,''string''=
,''toomany'')')
> > Now this the text can be highlighted, but if changed it will change rig=
ht back when return
> > is hit or another uicontrol is selected.
>
> However, there is a well-known limitation with edit boxes, that if you ar=
e editing
> and then you click on the figure instead of pressing return or on another=
 uicontrol,
> then the callback will not be called but the changed text will still be s=
hown.
>
> In order to do what the original poster wants without this possibility, t=
he original
> poster will (according to what I have read) work at the java level, proba=
bly by
> starting with a uicontrol and modifying the methods that that particular =
control
> uses. I believe the relevant code had been shown in the past; if I were t=
o search
> for it, I would start by examining Yair Altman's old postings.
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous posti=
ngs.
> Please review questions before posting them. Be specific. Use examples of=
 what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and=
 value
> relationships -- what if we scrambled your data or used -Inf, NaN, or com=
plex(rand,rand)?

Thank you for pointing me to Yair Altman's work! I found the solution
to what I originally had in mind on this group.

Subject: Matlab GUI static text

From: Matt Fig

Date: 24 Jan, 2009 16:29:02

Message: 8 of 16

trancemissionxxi@gmail.com wrote in message <179ee769-09fd-
> Thank you for pointing me to Yair Altman's work! I found the solution
> to what I originally had in mind on this group.


Would you post a link to what you found?




'nu lbb@aoh.ammpo eY avoo n khgaa'eau oyptt iMEca:eeochtil

Subject: Matlab GUI static text

From: Yair Altman

Date: 25 Jan, 2009 07:37:13

Message: 9 of 16

"Matt Fig" <spamanon@yahoo.com> wrote in message...
> > Thank you for pointing me to Yair Altman's work! I found the solution
> > to what I originally had in mind on this group.
>
>
> Would you post a link to what you found?


h = uicontrol('style','edit','string','1234567890');
hj = findjobj(h,'-nomenu'); % get the underlying java element
set(hj,'Editable',0);

Findjobj can be found on the File Exchange. You can use another of my submissions (UiInspect) to inspect the java element's methods, properties and callbacks.

Alternately, instead of using Matlab's internal uicontrol and modifying its underlying java element, you can use a Java Swing element directly using Matlab's javacomponent or my uicomponent (on the File Exchange) functions.

Yair Altman

Subject: Matlab GUI static text

From: trancemissionxxi@gmail.com

Date: 25 Jan, 2009 09:57:01

Message: 10 of 16

On Jan 24, 11:37=A0pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> "Matt Fig" <spama...@yahoo.com> wrote in message...
> > > Thank you for pointing me to Yair Altman's work! I found the solution
> > > to what I originally had in mind on this group.
>
> > Would you post a link to what you found?
>
> h =3D uicontrol('style','edit','string','1234567890');
> hj =3D findjobj(h,'-nomenu'); =A0% get the underlying java element
> set(hj,'Editable',0);
>
> Findjobj can be found on the File Exchange. You can use another of my sub=
missions (UiInspect) to inspect the java element's methods, properties and =
callbacks.
>
> Alternately, instead of using Matlab's internal uicontrol and modifying i=
ts underlying java element, you can use a Java Swing element directly using=
 Matlab's javacomponent or my uicomponent (on the File Exchange) functions.
>
> Yair Altman

Matt,

Yair's solution above is exactly what I'm using. Notice also that you
can call findjobj only when the gui is visible (after the opening
function, I wanted the text property to become uneditable as soon as
the gui shows up).

Subject: Matlab GUI static text

From: Matt Fig

Date: 25 Jan, 2009 23:05:28

Message: 11 of 16

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> h = uicontrol('style','edit','string','1234567890');
> hj = findjobj(h,'-nomenu'); % get the underlying java element
> set(hj,'Editable',0);
>
> Findjobj can be found on the File Exchange. You can use another of my submissions (UiInspect) to inspect the java element's methods, properties and callbacks.
>
> Alternately, instead of using Matlab's internal uicontrol and modifying its underlying java element, you can use a Java Swing element directly using Matlab's javacomponent or my uicomponent (on the File Exchange) functions.
>
> Yair Altman

Fantastic Yair! I wonder though, what are your thoughts on the stability of using hj across versions? Are these like undocumented properties that may be subject to change? Thanks for your FEX contributions :)




>wYTXRep`ZR^eR`pJp6RRS_wp\p^VpfpaV~]g1YpjeZ]`a_R`VRYV``fST+

Subject: Matlab GUI static text

From: Yair Altman

Date: 25 Jan, 2009 23:56:04

Message: 12 of 16

"Matt Fig" <spamanon@yahoo.com> wrote...

> Fantastic Yair! I wonder though, what are your thoughts on the stability of using hj across versions? Are these like undocumented properties that may be subject to change? Thanks for your FEX contributions :)


Well, Mathworks say that the entire Java underbelly of Matlab is unsupported and prone to change in some upcoming version. In practice, it has been around for many years, more or less in the current state since version 7.0 regarding the major stuff. Also, much of Matlab now relies on Java. So you might be tempted to think that it's unlikely to be killed anytime soon. But if you look closely you'll see that there's only one small link (at least only one that I found) from Matlab to the Java underbelly, and that's the figure's undocumented JavaFrame property. The moment Mathworks discontinues this property, findjobj will no longer work. In R2008b it appears that's their plan, since they started issuing a warning (MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame) when using this property. As long as you stick with existing versions you're ok, but there's no promise for future versions.

Yair Altman

Subject: findjobj failed in MATLAB 2009a

From: Patrick

Date: 11 Aug, 2009 17:54:19

Message: 13 of 16

It appears that findjobj failed in MATLAB R2009a.
I used GUIDE to set up a gui. Breaking point in the code, I called
>> j_obj = findjobj(h_obj); // e.g. obj is a slider
where h_obj is the handle to an uicontrol.
The returned j_obj is empty, no matter what is h_obj, even when there is no argument.

I tried the same with MATLAB 2007b, findjobj worked as advertized.

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <gliu6k$pku$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote...
>
> > Fantastic Yair! I wonder though, what are your thoughts on the stability of using hj across versions? Are these like undocumented properties that may be subject to change? Thanks for your FEX contributions :)
>
>
> Well, Mathworks say that the entire Java underbelly of Matlab is unsupported and prone to change in some upcoming version. In practice, it has been around for many years, more or less in the current state since version 7.0 regarding the major stuff. Also, much of Matlab now relies on Java. So you might be tempted to think that it's unlikely to be killed anytime soon. But if you look closely you'll see that there's only one small link (at least only one that I found) from Matlab to the Java underbelly, and that's the figure's undocumented JavaFrame property. The moment Mathworks discontinues this property, findjobj will no longer work. In R2008b it appears that's their plan, since they started issuing a warning (MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame) when using this property. As long as you stick with existing versions you're ok, but there's no promise for future versions.
>
> Yair Altman

Subject: findjobj failed in MATLAB 2009a

From: Patrick

Date: 11 Aug, 2009 17:54:19

Message: 14 of 16

It appears that findjobj failed in MATLAB R2009a.
I used GUIDE to set up a gui. Breaking point in the code, I called
>> j_obj = findjobj(h_obj); // e.g. obj is a slider
where h_obj is the handle to an uicontrol.
The returned j_obj is empty, no matter what is h_obj, even when there is no argument.

I tried the same with MATLAB 2007b, findjobj worked as advertized.

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <gliu6k$pku$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote...
>
> > Fantastic Yair! I wonder though, what are your thoughts on the stability of using hj across versions? Are these like undocumented properties that may be subject to change? Thanks for your FEX contributions :)
>
>
> Well, Mathworks say that the entire Java underbelly of Matlab is unsupported and prone to change in some upcoming version. In practice, it has been around for many years, more or less in the current state since version 7.0 regarding the major stuff. Also, much of Matlab now relies on Java. So you might be tempted to think that it's unlikely to be killed anytime soon. But if you look closely you'll see that there's only one small link (at least only one that I found) from Matlab to the Java underbelly, and that's the figure's undocumented JavaFrame property. The moment Mathworks discontinues this property, findjobj will no longer work. In R2008b it appears that's their plan, since they started issuing a warning (MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame) when using this property. As long as you stick with existing versions you're ok, but there's no promise for future versions.
>
> Yair Altman

Subject: Matlab GUI static text

From: Jan Simon

Date: 11 Aug, 2009 20:05:19

Message: 15 of 16

Dear trancemissionxxi!

> I have a question related to GUI development. I would like to have a
> text in the GUI that is selectable but cannot be changed.
>
> If I use 'text', then the string is not selectable by mouse. If I use
> 'edit' then the text is selectable but can also be changed.
>
> Is there any property I can set to make the text selectable but not
> changeable (in 'text' or 'edit' styles)?

Beside the really fancy Java methods, why is a TEXT obejct not selectable?
  TextH = text(0.5, 0.5, 'Click me', 'ButtonDownFcn', 'set(gcbo, ''Selected'', ''on'')');
It can be copied e.g. through a context menu or by a keypress function. E.g. the ButtonDownFcn can be far more powerful, e.g. by deselecting all other children of the figure. Then a keypress function can catch the [C] key and search for the currently selected object. If it is a TEXT, its string is copied. There is no danger of editing the text accidently.

This methof does not call undocumented Java methods and perhaps it satisfies your needs?

Kind regards, Jan

Subject: Matlab GUI static text

From: brigette Riley

Date: 8 Sep, 2009 16:48:02

Message: 16 of 16

see the following:

function [] = GUI_13()
% Demonstrate an edit text which has copyable but unchangeable text.
% Also creates a pushbutton which will print the contents of the
% editbox to the command line.
%
% Suggested exercise: Notice that the text can be cut (as well as copied).
% Alter the keypressfcn to eliminate this.
%
% Author: Matt Fig
% Date: 7/15/2009

S.fh = figure('units','pixels',...
              'position',[300 300 400 120],...
              'menubar','none',...
              'name','GUI_13',...
              'numbertitle','off',...
              'resize','off');
S.ed = uicontrol('style','edit',...
                 'unit','pix',...
                 'position',[30 70 340 30],...
                 'string','This text can be copied but not changed');
S.pb = uicontrol('style','push',...
                 'unit','pix',...
                 'position',[30 30 340 30],...
                 'string','Print to screen');
set([S.ed,S.pb],{'callback'},{{@ed_call,S};{@pb_call,S}}) % Set callbacks.
set(S.ed,'keypressfcn',{@ed_kpfcn,S}) % set keypressfcn.

function [] = pb_call(varargin)
% callback for pushbutton
S = varargin{3}; % Get the structure.
disp(get(S.ed,'string')) % Print to the command line.


function [] = ed_call(varargin)
% Callback for edit
S = varargin{3}; % Get the structure.
set (S.ed,'string','This text can be copied but not changed');


function [] = ed_kpfcn(varargin)
% Keypressfcn for edit
[K,S] = varargin{[2 3]};

if isempty(K.Modifier)
        uicontrol(S.pb)
        set (S.ed,'string','This text can be copied but not changed');
elseif ~strcmp(K.Key,'c') && ~strcmp(K.Modifier{1},'control')
        uicontrol(S.pb)
        set (S.ed,'string','This text can be copied but not changed');
end

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