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

How to correctly declare a JTree in Matlab ?

100 views
Skip to first unread message

{{**AleX**}}

unread,
Nov 16, 2009, 4:18:25 AM11/16/09
to
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

Yair Altman

unread,
Nov 16, 2009, 6:35:18 AM11/16/09
to
"{{**AleX**}}" <alexandr...@gmail.com> wrote in message <db277c08-8c43-4e69...@d10g2000yqh.googlegroups.com>...


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

0 new messages