According to the Oracle Java tutorial, you can just use undefined mode for programmed bars in a swing:
yourProgressBar.setIndeterminate(true);
Sometimes you cannot immediately determine the length of a long task, or the task may remain in the same completion state for a long time. You can show the work without tangible progress by setting the progress bar in undefined mode. The runtime progress bar displays an animation indicating that work is in progress.
source share