在MATLAB中的框内显示树结构

时间:2011-10-29 14:00:19

标签: user-interface matlab treeview tree jtree

我有一个问题是看到由以下代码创建的树结构。我希望树框实现窗格的内部,句柄是hPanLeft。但是,如果我使用规范化单位,我会得到NaN和Inf作为树结构的Position属性。我不明白出了什么问题。

  function example
    import javax.swing.*
    import javax.swing.tree.*;
    f = figure;
    hPanRight = uipanel('Parent',f,'Units','normalized','Position',...
        [0.5 0 0.5 0.5]);
    hPanLeft = uipanel('Parent',f,'Units','normalized','Position',...
        [0 0.5 0.5 0.5]);
    [tree, container]= uitree('v0');
    set(container,'Parent',hPanLeft);
    set(tree, 'Units', 'normalized');
    set(tree,'Position',[0 0 1 1]);
    get(tree,'Position'),
    root = uitreenode('v0','root','MAIN',[],false);
    Nodo1 = uitreenode('v0','Nodo1','LEAF 1',[],true);
    Nodo2 = uitreenode('v0','Nodo2','LEAF 2',[],true);
    Nodo3 = uitreenode('v0','Nodo3','LEAF 3',[],true);
    root.add(Nodo1);
    root.add(Nodo2);
    root.add(Nodo3);
    treeModel = DefaultTreeModel(root);
    tree.setModel(treeModel);
    jtree = handle(tree.getTree,'CallbackProperties');
    tree.setSelectedNode(root);
end

1 个答案:

答案 0 :(得分:1)

您想要设置容器的position属性而不是树对象句柄:

[tree,container] = uitree('v0');
set(container, 'Parent',hPanLeft);
set(container, 'Units','normalized', 'Position',[0 0 1 1]);

screenshot

请记住,UITREE是一个无证件的功能。您可能希望在此组件上阅读此series of articles