TreeExpansionMonitor<DefaultMutableTreeNode> (final JTree tree, final BiPredicate<? super DefaultMutableTreeNode, ? super DefaultMutableTreeNode> equality) { return new TreeExpansionMonitor<>(tree) { @Override protected TreePath findPathByNode(final DefaultMutableTreeNode node) { Enumeration<TreeNode> enumeration = ((DefaultMutableTreeNode)tree.getModel().getRoot()).breadthFirstEnumeration(); while (enumeration.hasMoreElements()) { final TreeNode nextElement = enumeration.nextElement(); if (nextElement instanceof DefaultMutableTreeNode child) { if (equality.test(child, node)) { return new TreePath(child.getPath()); } } } return null; } }; }