void (long total, long progress) { if (total == progress) { stopLoading(); return; } boolean isDeterminate = total > 0 && progress > 0; JProgressBar progressBar = getProgressBar(); boolean isProgressBarIndeterminate = progressBar.isIndeterminate(); if (isDeterminate) { startLoading(); progressBar.setValue(Math.toIntExact(progress * 100 / total)); if (isProgressBarIndeterminate) { progressBar.setIndeterminate(false); } } else if (!isProgressBarIndeterminate) { progressBar.setIndeterminate(true); } }