void () { List<Class<?>> configuredClasses = myManager.getConfiguredClasses(myProject); configuredClasses.sort(Comparator.comparingInt(ConfigureClientPropertiesDialog::getInheritanceLevel)); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultTreeModel treeModel = new DefaultTreeModel(root); Map<Class<?>, DefaultMutableTreeNode> classToNodeMap = new HashMap<>(); for (Class<?> cls : configuredClasses) { DefaultMutableTreeNode parentNode = root; Class<?> superClass = cls.getSuperclass(); while (superClass != null) { if (classToNodeMap.containsKey(superClass)) { parentNode = classToNodeMap.get(superClass); break; } superClass = superClass.getSuperclass(); } DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(cls); classToNodeMap.put(cls, childNode); parentNode.add(childNode); } myClassTree.setModel(treeModel); if (root.getChildCount() > 0) { myClassTree.expandRow(0); myClassTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); myClassTree.getSelectionModel().setSelectionPath(new TreePath(new Object[]{root, root.getFirstChild()})); } }