newSpringer newSpringer - 1 year ago 120
Java Question

JTree: How to get the path of a selected node

Is there a way to get the selected path of a selected node in a JTree like using something like

String pathForNode = JTree.getLastSelectedPathComponent().getPath().toString();

Answer Source

I used this:

    jTreeVarSelectedPath = "";
    Object[] paths = jTreeDirectorios.getSelectionPath().getPath();
    for (int i=0; i<paths.length; i++) {
        jTreeVarSelectedPath += paths[i];
        if (i+1 <paths.length ) {
            jTreeVarSelectedPath += File.separator;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download