private void collapsePath(final TreePath treePath, final TaskMonitor monitor) {
		runOnSwingThread(() -> {
			if (monitor.isCancelled()) {
				return; // we can be cancelled while waiting for Swing to run us
			}

			jTree.collapsePath(treePath);
		});
	}
A GTree task to fully collapse a tree
Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/tasks/GTreeCollapseAllTask.java