Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

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

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:ser321.media.MediaJavaClient.java

public void valueChanged(TreeSelectionEvent e) {
    try {/*from ww w  .j a va 2s.  com*/
        tree.removeTreeSelectionListener(this);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

        if (node != null) {
            String nodeLabel = (String) node.getUserObject();
            debug("In valueChanged. Selected node labelled: " + nodeLabel);
            // is this a terminal node?
            if (node.getChildCount() == 0 && (node != (DefaultMutableTreeNode) tree.getModel().getRoot())) {
                JSONObject jObj = new JSONObject();
                jObj = cc.get(nodeLabel);

                titleJTF.setText(nodeLabel);
                albumJTF.setText(jObj.getString("album"));
                authorJTF.setText(jObj.getString("author"));
                genreJTF.setText(jObj.getString("genre"));
                fileNameJTF.setText(jObj.getString("filename"));
                if (jObj.getString("mediaType").equals("0"))
                    typeJCB.setSelectedIndex(0);
                else
                    typeJCB.setSelectedIndex(1);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    tree.addTreeSelectionListener(this);
}

From source file:streamme.visuals.Main.java

private void fillTree(JSONObject json, DefaultMutableTreeNode parent) {
    DataNode folderDN = new DataNode(json.getInt("id"), json.getString("name"), true);
    DefaultMutableTreeNode folder = new DefaultMutableTreeNode(folderDN);

    for (Object obj : json.getJSONArray("folders")) {
        JSONObject jsonObj = (JSONObject) obj;
        fillTree(jsonObj, folder);/*from  ww  w  .j  a v  a 2  s .com*/
    }

    for (Object obj : json.getJSONArray("files")) {
        JSONObject jsonObj = (JSONObject) obj;
        DataNode fileDN = new DataNode(jsonObj.getInt("id"), jsonObj.getString("name"), false);
        DefaultMutableTreeNode file = new DefaultMutableTreeNode(fileDN);
        tree_model.insertNodeInto(file, folder, folder.getChildCount());
    }
    tree_model.insertNodeInto(folder, parent, parent.getChildCount());
}