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:
Problem with TreeView(uitree) and UIContextMenu

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Dennis B.

Date: 30 Jan, 2013 14:56:08

Message: 1 of 7

Hello Community,

I have a small Problem setting up a my uiContextmenu for my TreeView(uitree):

------------------------------------------------------------------------
Code:

%Get Tree
JavaTree_ja = hMainDlgTree_ja.getTree;

%Create Context Menu
hContextMenu = uicontextmenu('Tag','cmnu_TreeContextMenu');

...
set(JavaTree_ja,'MouseClickedCallback','sc_maindlggui',hMainDlg,'mdtreenouseclick'});
setappdata(JavaTree_ja,'UIContextMenu',hContextMenu);
JavaTree_ja.setRightSelectionEnabled(1);

------------------------------------------------------------------------

Because of using set-Function i get the Warning "MATLAB:hg:PossibleDeprecatedJavaSetHGProperty" (or "MATLAB:hg:JavaSetHGProperty" before Matlab 2012b).
But setappdata seems not working for this property. The contextmenu does not popup.

Also i found no java-property for access JavaTree_ja directly.

Anyone an idea to do this without warnings?

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Yair Altman

Date: 30 Jan, 2013 20:16:08

Message: 2 of 7

"Dennis B." wrote in message <kebca8$9f8$1@newscl01ah.mathworks.com>...
> Hello Community,
>
> I have a small Problem setting up a my uiContextmenu for my TreeView(uitree):
>
> ------------------------------------------------------------------------
> Code:
>
> %Get Tree
> JavaTree_ja = hMainDlgTree_ja.getTree;
>
> %Create Context Menu
> hContextMenu = uicontextmenu('Tag','cmnu_TreeContextMenu');
>
> ...
> set(JavaTree_ja,'MouseClickedCallback','sc_maindlggui',hMainDlg,'mdtreenouseclick'});
> setappdata(JavaTree_ja,'UIContextMenu',hContextMenu);
> JavaTree_ja.setRightSelectionEnabled(1);
>
> ------------------------------------------------------------------------
>
> Because of using set-Function i get the Warning "MATLAB:hg:PossibleDeprecatedJavaSetHGProperty" (or "MATLAB:hg:JavaSetHGProperty" before Matlab 2012b).
> But setappdata seems not working for this property. The contextmenu does not popup.
>
> Also i found no java-property for access JavaTree_ja directly.
>
> Anyone an idea to do this without warnings?


1. warnings -
jObject = handle(JavaTree_ja, 'CallbackProperties');
set(jObject, ...)

2. getappdata - this was indeed removed for some inexplicable reason by MathWorks (I believe in R2012a). Use try/catch and/or the object's UserData or some other means of storing your data persistently. Bad, bad, MathWorks!

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Dennis B.

Date: 31 Jan, 2013 07:53:08

Message: 3 of 7

Hi Yair - thanks for your response.
After changing my Code to:

------------------------------------------------------------

jObject_ja = handle(JavaTree_ja, 'CallbackProperties');
set(jObject_ja,'MouseClickedCallback',{'sc_maindlggui',hMainDlg,'mdtreenouseclick'});

setappdata(JavaTree_ja,'UIContextMenu',hContextMenu); %BARD-23-11-11: use "setappdata" for Java-GUI instead of "set"

JavaTree_ja.setRightSelectionEnabled(1); %set(JavaTree_ja,'rightSelectionEnabled','on');

------------------------------------------------------------

i get an error "Invalid object handle" at setappdata and if i change the order ("handle" and "set" at lastt) no error occurs, but also no Context-PopUp shows up.

Any idea?

Greetings
D.B.

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Steven_Lord

Date: 31 Jan, 2013 15:05:35

Message: 4 of 7



"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
news:kebv28$qov$1@newscl01ah.mathworks.com...

*snip*

> 2. getappdata - this was indeed removed for some inexplicable reason by
> MathWorks (I believe in R2012a). Use try/catch and/or the object's
> UserData or some other means of storing your data persistently. Bad, bad,
> MathWorks!

Could you clarify what you meant by this, Yair? I have release R2012b open
and it recognizes GETAPPDATA just fine.

>> version
ans =
8.0.0.783 (R2012b)

>> help getappdata
 getappdata Get value of application-defined data.
   VALUE = getappdata(H, NAME) gets the value of the
   application-defined data with name specified by NAME in the
   object with handle H. If the application-defined data does
   not exist, an empty matrix will be returned in VALUE.
*snip the rest*

The online documentation also indicates that GETAPPDATA is still present.

http://www.mathworks.com/help/matlab/ref/getappdata.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Yair Altman

Date: 31 Jan, 2013 18:39:08

Message: 5 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <kee17v$kpf$1@newscl01ah.mathworks.com>...
>
>
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> news:kebv28$qov$1@newscl01ah.mathworks.com...
>
> *snip*
>
> > 2. getappdata - this was indeed removed for some inexplicable reason by
> > MathWorks (I believe in R2012a). Use try/catch and/or the object's
> > UserData or some other means of storing your data persistently. Bad, bad,
> > MathWorks!
>
> Could you clarify what you meant by this, Yair? I have release R2012b open
> and it recognizes GETAPPDATA just fine.
>
> >> version
> ans =
> 8.0.0.783 (R2012b)
>
> >> help getappdata
> getappdata Get value of application-defined data.
> VALUE = getappdata(H, NAME) gets the value of the
> application-defined data with name specified by NAME in the
> object with handle H. If the application-defined data does
> not exist, an empty matrix will be returned in VALUE.
> *snip the rest*
>
> The online documentation also indicates that GETAPPDATA is still present.
>
> http://www.mathworks.com/help/matlab/ref/getappdata.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Hi Steve - what I meant was that getappdata has stopped working for pure (un-handled) Java objects within the specific context of a callback function - it continues to work for regular HG handles, and even Java objects outside callbacks. I should probably have made this clear in my post above, so thanks for the chance to clarify.

If this would help get TMW to restore getappdata also for Java objects in callbacks, then all the better. When I first contacted the developers about this, I basically got a shrug... - using getappdata/setappdata this way is apparently not a supported functionality for some reason.

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Yair Altman

Date: 31 Jan, 2013 18:43:08

Message: 6 of 7

"Dennis B." wrote in message <ked7t4$jp6$1@newscl01ah.mathworks.com>...
> Hi Yair - thanks for your response.
> After changing my Code to:
>
> ------------------------------------------------------------
>
> jObject_ja = handle(JavaTree_ja, 'CallbackProperties');
> set(jObject_ja,'MouseClickedCallback',{'sc_maindlggui',hMainDlg,'mdtreenouseclick'});
>
> setappdata(JavaTree_ja,'UIContextMenu',hContextMenu); %BARD-23-11-11: use "setappdata" for Java-GUI instead of "set"
>
> JavaTree_ja.setRightSelectionEnabled(1); %set(JavaTree_ja,'rightSelectionEnabled','on');
>
> ------------------------------------------------------------
>
> i get an error "Invalid object handle" at setappdata and if i change the order ("handle" and "set" at lastt) no error occurs, but also no Context-PopUp shows up.
>
> Any idea?
>
> Greetings
> D.B.


Of course you get an error - read the documentation for set and setappdata - they are completely different. set is used to update an object's property (e.g., 'UIContextMenu'); setappdata is used to store some user-named value.

For a context menu to be active you need to *set* the UIContextMenu property; if you don't want the warning you need to set not the basic java object but the handle()'ed object. In short - you made a whole mess of things, so re-read my post carefully... (or my Matlab-Java programming book)

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Problem with TreeView(uitree) and UIContextMenu

From: Dennis B.

Date: 6 Feb, 2013 14:46:09

Message: 7 of 7

Ahh, i got it:

hJavaTree_ja = handle(JavaTree_ja, 'CallbackProperties');
set(hJavaTree_ja,'MouseClickedCallback',{'sc_maindlggui',hMainDlg,'mdtreenouseclick'});
setappdata(hJavaTree_ja,'UIContextMenu',hContextMenu);

I allready thought that i tried this, but after looking into your book and trying it again it works now.

Anyway, thanks for helping.

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