package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;

public final class MainPanel extends JPanel {
    private final JTextField textField = new JTextField("soccer");
    public MainPanel() {
        super(new BorderLayout());
        final JTree tree1 = new JTree();
        tree1.setExpandsSelectedPaths(false);

        final JTree tree2 = new JTree();
        tree2.setExpandsSelectedPaths(true);

        JPanel p1 = new JPanel(new GridLayout(1, 2));
        p1.setBorder(BorderFactory.createTitledBorder("setExpandsSelectedPaths"));
        p1.add(makeTitledScrollPane(tree1, "false"));
        p1.add(makeTitledScrollPane(tree2, "true"));

        JPanel p2 = new JPanel(new BorderLayout());
        p2.add(textField);
        p2.add(new JButton(new AbstractAction("Select") {
            @Override public void actionPerformed(ActionEvent e) {
                String q = textField.getText().trim();
                searchTree(tree1, tree1.getPathForRow(0), q);
                searchTree(tree2, tree2.getPathForRow(0), q);
            }
        }), BorderLayout.EAST);

        add(p1);
        add(p2, BorderLayout.SOUTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JScrollPane makeTitledScrollPane(Component view, String title) {
        JScrollPane scroll = new JScrollPane(view);
        scroll.setBorder(BorderFactory.createTitledBorder(title));
        return scroll;
    }
    private static void searchTree(JTree tree, TreePath path, String q) {
        TreeNode node = (TreeNode) path.getLastPathComponent();
        if (Objects.isNull(node)) {
            return;
        }
        if (node.toString().equals(q)) {
            tree.addSelectionPath(path);
        }
        if (!node.isLeaf() && node.getChildCount() >= 0) {
            Enumeration e = node.children();
            while (e.hasMoreElements()) {
                searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
            }
        }
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        //frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -1656,34 +1656,18 @@
     
-TreeNode node = (TreeNode)
+Object o =
  pat
@@ -1708,29 +1708,30 @@
 if (
-Objects.isNull(n
+o instanceof TreeN
 ode)
-)
  %7B%0A 
@@ -1745,26 +1745,42 @@
     
+T
 re
-turn;%0A    
+eNode node = (TreeNode) o;%0A
     
-%7D%0A
     
@@ -1824,24 +1824,28 @@
             
+  
+  
 tree.addSele
@@ -1869,26 +1869,32 @@
         
-%7D%0A
+    %7D%0A  
         
 if (!nod
@@ -1881,24 +1881,26 @@
 %7D%0A          
+  
 if (!node.is
@@ -1950,16 +1950,20 @@
         
+    
 Enumerat
@@ -1999,16 +1999,20 @@
         
+  
+  
 while (e
@@ -2029,24 +2029,28 @@
 ements()) %7B%0A
+    
             
@@ -2111,24 +2111,42 @@
 ent()), q);%0A
+                %7D%0A
             

use o instanceof TreeNode instead of Objects.isNull(o)