Object (JTree tree) { final TreePath[] selectionPath = tree.getSelectionPaths(); if (selectionPath == null || selectionPath.length != 1) return null; final Object component = selectionPath[0].getLastPathComponent(); return getObject(component); }