List of usage examples for javax.swing JTree getModel
public TreeModel getModel()
TreeModel
that is providing the data. From source file:Main.java
public static DefaultMutableTreeNode buscarNodeByNombre(JTree jtree, String nodeStr) { DefaultMutableTreeNode node = null; TreeNode root = (TreeNode) jtree.getModel().getRoot(); Enumeration<?> e = root.children(); while (e.hasMoreElements()) { node = (DefaultMutableTreeNode) e.nextElement(); if ((node.getUserObject().toString()).contains(nodeStr)) { return node; }//from ww w . j a v a2s .c om } return null; }
From source file:Main.java
public static JComponent makeUI() { JTree tree = new JTree(); TreeModel model = tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); Enumeration e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); Object o = node.getUserObject(); if (o instanceof String) { node.setUserObject(new CheckBoxNode((String) o, false)); }//from w w w. j a v a 2 s . c om } tree.setEditable(true); tree.setCellRenderer(new CheckBoxNodeRenderer()); tree.setCellEditor(new CheckBoxNodeEditor()); tree.expandRow(0); return new JScrollPane(tree); }
From source file:Main.java
/** * Expand (or collapse) the children nodes of specified node of a JTree for a certain depth. * @param tree Tree of which we want to expand the nodes. * @param parent Parent node./*from w ww . j a va2s . c om*/ * @param expand <code>true</code> to expand the nodes. <code>false</code> to collapse the nodes. * @param depth Depth of children to expand or collapse. */ public static void expandNodes(JTree tree, TreePath parent, boolean expand, int depth) { if (parent == null || depth == 0) return; Object node = parent.getLastPathComponent(); if (node != null) { for (int i = 0; i < tree.getModel().getChildCount(node); i++) { Object child = tree.getModel().getChild(node, i); TreePath path = parent.pathByAddingChild(child); expandNodes(tree, path, expand, depth - 1); } } if (expand) tree.expandPath(parent); else tree.collapsePath(parent); }
From source file:Main.java
protected static void expandTree(JTree tree, TreePath path, Hashtable lookedAt) { Object node = path.getLastPathComponent(); if (lookedAt.containsKey(node)) return;/* w w w . j ava 2 s. co m*/ lookedAt.put(node, node); Vector paths = new Vector(); tree.makeVisible(path); int childCount = tree.getModel().getChildCount(node); for (int i = 0; i < childCount; i++) { Object child = tree.getModel().getChild(node, i); TreePath p = path.pathByAddingChild(child); expandTree(tree, p, lookedAt); } }
From source file:Main.java
public void expandAll(JTree tree) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root)); }
From source file:Main.java
public TreePath[] getPaths(JTree tree, boolean expanded) { TreeNode root = (TreeNode) tree.getModel().getRoot(); List<TreePath> list = new ArrayList<TreePath>(); getPaths(tree, new TreePath(root), expanded, list); return (TreePath[]) list.toArray(new TreePath[list.size()]); }
From source file:ca.phon.app.query.report.ReportTreeCellRenderer.java
@Override public Component getTreeCellRendererComponent(JTree arg0, Object arg1, boolean arg2, boolean arg3, boolean arg4, int arg5, boolean arg6) { JLabel lbl = (JLabel) super.getTreeCellRendererComponent(arg0, arg1, arg2, arg3, arg4, arg5, arg6); Section section = (Section) arg1;//from ww w . jav a 2 s . c om if (arg1 == arg0.getModel().getRoot()) { lbl.setIcon(rptIcon); } else { lbl.setIcon(icons.get(section.getClass())); } String lblText = StringUtils.strip(section.getName()); if (lblText == null || lblText.length() == 0) { lblText = "<html><i>Untitled</i></html>"; } lbl.setText(lblText); // if(arg1 instanceof ReportDesign) { // ReportDesign report = (ReportDesign)arg1; // lbl.setText(report.getName()); // lbl.setIcon(rptIcon); // } else { // Section section = (Section)arg1; // lbl.setIcon(icons.get(section.getClass())); // // // lbl.setText(section.getName()); //// if(section instanceof Group) { //// lbl.setText("Group : " + section.getName()); //// } else { //// lbl.setText("Section : " + section.getName()); //// } // } return lbl; }
From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java
public void generateTree(JTree jTree, Scenario scenario, String stringa) { DefaultTreeModel model = (DefaultTreeModel) jTree.getModel(); TreeNode root = (TreeNode) model.getRoot(); if (root != null) { analisiRicorsivaAggiuntaIstanza(root, scenario, model, stringa); }//from w ww . ja v a2s . c om }
From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetAlberi.java
public void creaWidgetAlbero(JTree albero, Component source, Component target, boolean sourceFlag) { analisiRicorsiva(albero.getModel(), albero.getModel().getRoot()); scansioneAlbero(albero, source, target, sourceFlag); }
From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java
public void generateTree(JTree jTree, Scenario scenario, TopComponent topComponentAdded) { Scenarios scenarios = (Scenarios) modello.getBean(Costanti.SCENARIOS); DefaultTreeModel model = (DefaultTreeModel) jTree.getModel(); TreeNode root = (TreeNode) model.getRoot(); if (root != null) { if (topComponentAdded != null) { analisiRicorsivaAggiuntaTC(root, scenario, model, topComponentAdded); } else if (scenarios.containsScenario(scenario)) { analizzaScenario((DefaultMutableTreeNode) root, scenario); } else {/* w w w . j a v a 2s .c om*/ analisiRicorsivaCancellaScenario(root, scenario, model); } } }