Here you can find the source of setExpandedOnEdt(JTree tree, TreePath path, boolean expanded)
public static void setExpandedOnEdt(JTree tree, TreePath path, boolean expanded)
//package com.java2s; //License from project: Open Source License import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.tree.TreePath; public class Main { public static void setExpandedOnEdt(JTree tree, TreePath path, boolean expanded) { if (expanded) { expandPathOnEdt(tree, path); } else {// w ww . j ava2 s. c o m collapsePathOnEdt(tree, path); } } public static void expandPathOnEdt(final JTree tree, final TreePath path) { SwingUtilities.invokeLater(new Runnable() { public void run() { tree.expandPath(path); } }); } public static void collapsePathOnEdt(final JTree tree, final TreePath path) { SwingUtilities.invokeLater(new Runnable() { public void run() { tree.collapsePath(path); } }); } }