开发者

problems with a JTree, it doesn´t display

I´ve done a tree but it doesn´t display...even it doesn´t allow other components to appear... here is part of the code.

  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.getSelectio开发者_StackOverflownModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);  

    //treeView = new JScrollPane(treeInicio);
    }

I don´t know if I have to add to my panel treeInicio or treeView... Here´s the rest of the code

 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));  

thanks for your time


Where do you add your JTree to a Container that is made visible?


Read the JTree API and follow the link to the Swing tutorial on "How to Use Trees" for a working example. Then you can compare the working code with your code to see what it different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜