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:
How to correctly declare a JTree in Matlab ?

Subject: How to correctly declare a JTree in Matlab ?

From: {{**AleX**}}

Date: 16 Nov, 2009 09:18:25

Message: 1 of 2

Dear All,

I need to display some data architecture as a TreeView (like Windos
Explorer) and have some return function to knwo which elements are
currently selected by the user.
I saw the uitree function in Matlab for such display settings but as
it's undocumented an maybe not planed for next releases I prefer to go
directly in Java components.
The following code produce what I want :
==========
  f = figure;
  p = uipanel('Position', [0 0 .2 1]);
  ppos = getpixelposition(p);
  [tree treecontainer] = javacomponent('javax.swing.JTree', ...
                            [0 0 ppos(3) ppos(4)], p);
=================
Two questions:
- How to instanciate the JTree components without using the
javacomponent function (which is also unsupported) ?
- How to modify the data structure : here it's display with some
initial data but I don't find the way to customize it ?

I other ways produce the same things please tell mel.

Thanks for your help & comments.
Alex

Subject: How to correctly declare a JTree in Matlab ?

From: Yair Altman

Date: 16 Nov, 2009 11:35:18

Message: 2 of 2

"{{**AleX**}}" <alexandre.gomilar@gmail.com> wrote in message <db277c08-8c43-4e69-a60d-f48af2206c67@d10g2000yqh.googlegroups.com>...
> Dear All,
>
> I need to display some data architecture as a TreeView (like Windos
> Explorer) and have some return function to knwo which elements are
> currently selected by the user.
> I saw the uitree function in Matlab for such display settings but as
> it's undocumented an maybe not planed for next releases I prefer to go
> directly in Java components.
> The following code produce what I want :
> ==========
> f = figure;
> p = uipanel('Position', [0 0 .2 1]);
> ppos = getpixelposition(p);
> [tree treecontainer] = javacomponent('javax.swing.JTree', ...
> [0 0 ppos(3) ppos(4)], p);
> =================
> Two questions:
> - How to instanciate the JTree components without using the
> javacomponent function (which is also unsupported) ?
> - How to modify the data structure : here it's display with some
> initial data but I don't find the way to customize it ?
>
> I other ways produce the same things please tell mel.
>
> Thanks for your help & comments.
> Alex


You need to use undocumented functionality - I'm afraid there is no way around this. But you were on the right track. After creating the JTree, you can add/process tree nodes as explained here: http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

As an alternative, use Matlab's built-in uitree and uitreenode functions. They have a detailed help section within the files (type: "edit uitree" and "edit uitreenode").

As an alternative, download my FindJObj utility from the File Exchange and see how I implemented the tree, including nodes, node-icons, dynamic tooltips and dynamic context-menus: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects

I think I'll post an article about trees in Matlab on my UndocumentedMatlab site soon, but this should give you a head start in the meantime.

Yair Altman
http://UndocumentedMatlab.com

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