newSpringer newSpringer - 6 months ago 29
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();


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;