我已經做了一棵樹,但它不會顯示...即使它不允許其他組件出現......這是代碼的一部分。JTree的問題,它不會顯示
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或樹視圖... Here's的代碼的其餘部分
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));
感謝您的時間
除非您知道問題出在哪裏,您怎麼知道要顯示的代碼的相關部分?出於這個原因(以及其他原因),我建議人們發佈SSCCE(http://pscode.org/sscce.html)。爲了使SSCCE更短,您可以創建一個默認的JTree,它已經填充了數據。 – 2010-10-28 08:48:00