VirtualFile (TreePath path) { Object component = path.getLastPathComponent(); if (component instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)component; Object userObject = node.getUserObject(); if (userObject instanceof FileNodeDescriptor descriptor) { return descriptor.getElement().getFile(); } } if (component instanceof FileNode) { FileNode node = (FileNode)component; return node.getFile(); } return null; }