void (final Node node, final int start, final int end, final @Nullable Runnable eachRunnable, final @Nullable Runnable endRunnable) { UIUtil.invokeAndWaitIfNeeded(() -> { for (int i = start; i <= end; i++) { Node eachFile = node.addChild("File " + i); myAutoExpand.add(eachFile.getElement()); eachFile.addChild("message 1 for " + i); eachFile.addChild("message 2 for " + i); if (eachRunnable != null) { eachRunnable.run(); } } if (endRunnable != null) { endRunnable.run(); } }); }