@Override
	public void run(TaskMonitor monitor) throws CancelledException {
		// add a callback for when/if the user cancels the layout, use a variable because
		// monitor uses a weak listener list and it would otherwise get garbage collected.
		CancelledListener cancelListener = this::taskCancelled;
		monitor.addCancelledListener(cancelListener);

		// add a listener so we are notified when the layout starts and ends
		VisualizationModel<AttributedVertex, AttributedEdge> model = viewer.getVisualizationModel();
		LayoutModel<AttributedVertex> layoutModel = model.getLayoutModel();
		Support support = layoutModel.getLayoutStateChangeSupport();
		Listener listener = this::layoutStateChanged;
		support.addLayoutStateChangeListener(listener);

		// start the layout - needs to be done on swing thread to prevent issues and intermediate
		// paints - should be changed in the future to not require it to be on the swing thread.
		Swing.runNow(() -> layoutTransitionManager.setLayout(layoutName));

		waitForLayoutTransition(model);

		support.removeLayoutStateChangeListener(listener);
		monitor.removeCancelledListener(cancelListener);
	}
Task to change the layout of the graph
Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/SetLayoutTask.java