CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > JProgressBar in Java Swing

Swing Tutorial

  • What Is Java Swing
  • First Program
  • What is AWT
  • Advantages of Swing Over AWT
  • JFrame
  • Swing Components
  • JLabel
  • JTextField
  • JPasswordField
  • JButton
  • Event Handling
  • FlowLayout
  • BorderLayout
  • GridLayout
  • GridBagLayout
  • BoxLayout
  • JPanel
  • JCheckBox
  • JRadioButton
  • Border Component
  • JComboBox
  • JList
  • JList with MVC
  • Mouse Event
  • Key Event
  • JMenuBar
  • JTextArea
  • Using Color
  • Use Font
  • Display Image/Icon
  • Dialog Box
  • JTable
  • JDesktopPane and JInternalFrame
  • JDesktopPane
  • JInternalFrame
  • Adapter Classes
  • Swing Timer
  • JScrollPane
  • JSlider
  • JProgressBar
  • JSeparator
  • JToolBar
  • ActionListener
  • ItemListener
  • Worker Thread
  • Nimbus Look and Feel
  • Home

JProgressBar in Java Swing

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 2 min read · 0 Comments
Share: in X

In Java, a JProgressBar is a graphical component that displays the progress of a task. It’s commonly used to show the advancement of tasks like file downloads, data processing, or any operation that takes time to complete.

Following a basic example of how to use the JProgressBar component:

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.Timer;

public class JProgressBarDemo extends JFrame {
	private JProgressBar progressBar;
	private JButton startButton;
	private Timer timer;
	private int progressValue = 0;

	public JProgressBarDemo() {
		setTitle("JProgressBar Demo");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new FlowLayout());

		progressBar = new JProgressBar(0, 100);
		progressBar.setPreferredSize(new Dimension(300, 30));
		add(progressBar);

		startButton = new JButton("Start");
		add(startButton);

		startButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				startButton.setEnabled(false); // Disable the button during progress
				timer.start(); // Start the timer to update the progress
			}
		});

		timer = new Timer(100, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (progressValue < 100) {
					progressValue++;
					progressBar.setValue(progressValue);
				} else {
					timer.stop(); // Stop the timer when progress reaches 100
					startButton.setEnabled(true); // Re-enable the button
					progressValue = 0; // Reset progress for future use
				}
			}
		});

		pack();
		setLocationRelativeTo(null); // Center the window
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				new JProgressBarDemo().setVisible(true);
			}
		});
	}

}

Output:

JProgressBar in Java Swing

Related Posts:

  • Event Handling in Java Swing
  • MySQL Commands for Developers
  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Control Statements in Java
  • Swing Worker Thread
  • Spring Boot Thread Pool Configuration: Optimizing…
Tags:guijavaswing
Was this article helpful?
← Previous ArticleJSlider in Java Swing
Next Article →JSeparator in Java Swing

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap