Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode.

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:Main.java

private void createNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode category = null;
    DefaultMutableTreeNode book = null;

    category = new DefaultMutableTreeNode("Books for Java Programmers");
    top.add(category);/*from  w  ww  .  j  a va 2 s.com*/

    book = new DefaultMutableTreeNode(new BookInfo("Java Tutorial"));
    category.add(book);
    book = new DefaultMutableTreeNode(new BookInfo("JDK"));
    category.add(book);
    book = new DefaultMutableTreeNode(new BookInfo("GUI"));
    category.add(book);
    book = new DefaultMutableTreeNode(new BookInfo("Guide"));
    category.add(book);

    book = new DefaultMutableTreeNode(new BookInfo("Language"));
    category.add(book);

    book = new DefaultMutableTreeNode(new BookInfo("SQL"));
    category.add(book);

    category = new DefaultMutableTreeNode("CSS");
    top.add(category);

    book = new DefaultMutableTreeNode(new BookInfo("Spec"));
    category.add(book);

    book = new DefaultMutableTreeNode(new BookInfo("Javascript"));
    category.add(book);
}

From source file:TreeUtil.java

public TreeUtil(String name, Object root) {
    itsMap.put(name, root);
    itsRootNode = new DefaultMutableTreeNode(name);
    itsTreeMap.put(name, itsRootNode);
}

From source file:Branch.java

public void init() {
    Container cp = getContentPane();
    root = new DefaultMutableTreeNode("root");
    tree = new JTree(root);
    // Add it and make it take care of scrolling:
    cp.add(new JScrollPane(tree), BorderLayout.CENTER);
    // Capture the tree's model:
    model = (DefaultTreeModel) tree.getModel();
    JButton test = new JButton("Press me");
    test.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (i < data.length) {
                child = new Branch(data[i++]).node();
                // What's the last one you clicked?
                chosen = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                if (chosen == null)
                    chosen = root;/*w w  w.ja v  a2  s .  c o m*/
                // The model will create the appropriate event.
                // In response, the tree will update itself:
                model.insertNodeInto(child, chosen, 0);
                // Puts the new node on the chosen node.
            }
        }
    });
    // Change the button's colors:
    test.setBackground(Color.BLUE);
    test.setForeground(Color.WHITE);
    JPanel p = new JPanel();
    p.add(test);
    cp.add(p, BorderLayout.SOUTH);
}

From source file:SortTreeDemo.java

protected void fillModel(SortTreeModel model, DefaultMutableTreeNode current) {
    PrettyFile pf = (PrettyFile) current.getUserObject();
    File f = pf.getFile();/*  w  w w.  j  av a 2  s  .c o m*/
    if (f.isDirectory()) {
        String files[] = f.list();
        // ignore "." files
        for (int i = 0; i < files.length; i++) {
            if (files[i].startsWith("."))
                continue;
            PrettyFile tmp = new PrettyFile(pf, files[i]);
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp);
            model.insertNodeInto(node, current);
            if (tmp.getFile().isDirectory()) {
                fillModel(model, node);
            }
        }
    }
}

From source file:MainClass.java

private DefaultMutableTreeNode makeShow(String title, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode show;/*from  www. j  av a 2  s . c o  m*/
    show = new DefaultMutableTreeNode(title);
    parent.add(show);
    return show;
}

From source file:Main.java

private DefaultMutableTreeNode processHierarchy(Object[] hierarchy) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(hierarchy[0]);
    DefaultMutableTreeNode child;
    for (int i = 1; i < hierarchy.length; i++) {
        Object nodeSpecifier = hierarchy[i];
        if (nodeSpecifier instanceof Object[]) {
            child = processHierarchy((Object[]) nodeSpecifier);
        } else {//from   w  w w  .  j  a va 2  s .c om
            child = new DefaultMutableTreeNode(nodeSpecifier);
        }
        node.add(child);
    }
    return (node);
}

From source file:TreeUtil.java

public TreeUtil(String name) {
    itsMap.put(name, new Object());
    itsRootNode = new DefaultMutableTreeNode(name);
    itsTreeMap.put(name, itsRootNode);
}

From source file:Main.java

protected void addFiles(File rootFile, DefaultTreeModel model, DefaultMutableTreeNode root) {
    for (File file : rootFile.listFiles()) {
        DefaultMutableTreeNode child = new DefaultMutableTreeNode(file);
        model.insertNodeInto(child, root, root.getChildCount());
        if (file.isDirectory()) {
            addFiles(file, model, child);
        }/*from w ww  .  ja va 2 s  .  c  o  m*/
    }
}

From source file:de.quadrillenschule.azocamsyncd.gui.ExploreWifiSDPanel.java

/**
 * Creates new form ExploreWifiSDPanel//from w w  w .j a va  2 s  .  c om
 */
public ExploreWifiSDPanel() {
    initComponents();
    rootNode = new DefaultMutableTreeNode("/");
    DefaultTreeModel dtm = new DefaultTreeModel(rootNode);
    remotejTree.setModel(dtm);
    remotejTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateSingleView();
        }
    });
    remotejTree.setCellRenderer(new TreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            JLabel retval = new JLabel(value.toString());
            AZoFTPFile myaffile = null;
            if (afs == null) {
                return retval;
            }
            for (AZoFTPFile af : afs) {
                if (new String(af.dir + af.ftpFile.getName()).equals(value.toString())) {
                    myaffile = af;
                    break;
                }
            }
            try {
                if (!myaffile.ftpFile.isDirectory()) {
                    if (!localStorage.getLocalFile(myaffile).exists()) {

                        if (!localStorage.isFileSynced(myaffile)) {
                            retval.setForeground(new Color(0, 20, 100));
                        }
                    } else {
                        retval.setForeground(new Color(20, 100, 0));
                    }
                }
            } catch (Exception ex) {
                //           Logger.getLogger(ExploreWifiSDPanel.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (selected) {
                retval.setOpaque(true);
                retval.setBackground(Color.darkGray);
            }
            return retval;
        }
    });
}

From source file:StAXStreamTreeViewer.java

private void addStartDocumentNodes(XMLStreamReader reader, DefaultMutableTreeNode current) {
    DefaultMutableTreeNode version = new DefaultMutableTreeNode(reader.getVersion());
    current.add(version);/*from w w w.  j  a v a  2 s. com*/

    DefaultMutableTreeNode standalone = new DefaultMutableTreeNode(reader.isStandalone());
    current.add(standalone);

    DefaultMutableTreeNode standaloneSet = new DefaultMutableTreeNode(reader.standaloneSet());
    current.add(standaloneSet);

    DefaultMutableTreeNode encoding = new DefaultMutableTreeNode(reader.getEncoding());
    current.add(encoding);

    DefaultMutableTreeNode declaredEncoding = new DefaultMutableTreeNode(reader.getCharacterEncodingScheme());
    current.add(declaredEncoding);
}