我已经做了一棵树,但是它不显示...甚至不允许其他组件出现...这是代码的一部分。

  private JScrollPane treeView;
  private JTree treeInicio;
  protected DefaultTreeModel treeModel;
  DefaultMutableTreeNode top = new DefaultMutableTreeNode("Root");
  private Toolkit toolkit = Toolkit.getDefaultToolkit();
  DefaultTreeCellRenderer iconoDiagrama;

  public void tree(){

   iconoDiagrama= (DefaultTreeCellRenderer)treeInicio.getCellRenderer();
   iconoDiagrama.setLeafIcon(new ImageIcon("Icono.gif"));

   DefaultMutableTreeNode plant1 = new DefaultMutableTreeNode("plantilla 1");
   DefaultMutableTreeNode plant2 = new DefaultMutableTreeNode("plantilla 2");
   DefaultMutableTreeNode diag11 = new DefaultMutableTreeNode("diagrama 11");
   DefaultMutableTreeNode diag12 = new DefaultMutableTreeNode("diagrama 12");
   DefaultMutableTreeNode diag13 = new DefaultMutableTreeNode("diagrama 13");
   DefaultMutableTreeNode diag21 = new DefaultMutableTreeNode("diagrama 21");
   DefaultMutableTreeNode diag22 = new DefaultMutableTreeNode("diagrama 22");

   top.add(plant1);
   plant1.add(diag11);
   plant1.add(diag12);
   plant1.add(diag13);
   top.add(plant2);
   plant2.add(diag21);
   plant2.add(diag22);

    treeModel = new DefaultTreeModel(top);
    treeInicio = new JTree(treeModel);
    treeInicio.setEditable(true);
          treeInicio.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //treeView = new JScrollPane(treeInicio);
    }


我不知道是否必须添加到面板上treeInicio或treeView ...
这是其余的代码

 plantillas.add(treeInicio, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));


谢谢你的时间

最佳答案

您在哪里将JTree添加到可见的Container中?

10-06 09:26