Progress Bar In Java With Source Code

The Progress Bar In Java is a component of the Java Swing package. JProgressBar visualizes the progress of a specific task.

JProgressBar displays the percentage of a task’s completion. As the work is completed, the progress meter fills up.

In addition to displaying the percentage of work completion, it can also display some text.

What Is Progress Bar In Java?

A progress bar is a widget that shows how far a long task is progressing, such as a file download or transfer. The JProgressbar class is used to make a progress bar in Swing.

You can use JProgressBar to make a vertical or horizontal progress bar.

Commonly used methods of JProgressBar

  • void SetString(String s) – Set the String s as the progress string’s value.
  • void SetValue(int n) – Set the current value of the progress bar to n.
  • void SetMinimum(int n) – sets the minimum value of the progress bar to the value n.
  • void SetMaxamum(int n) – sets the maximum value of the progress bar to n.
  • String getString() – get the string representation of the progress bar’s current value
  • int getMinimum() – The progress bar’s minimum value is returned.
  • int getMaximum() – The maximum value of the progress bar is returned.

Constructor of JProgressBar

  • JProgressBar() – a progress bar with no text is made.
  • JProgressBar(int orientation) – produces a progress bar with the orientation you specify. if SwingConstants is true If the input VERTICAL is supplied, a vertical progress bar is created if SwingConstants is true. When the parameter HORIZONTAL is used, a horizontal progress bar is created.
  • JProgressBar(int min, int max) – Creates a progress bar with a minimum and maximum value that you specify.
  • JProgressBar(int orientation, int min, int max) – produces a progress bar with a minimum and maximum value, as well as an orientation. if SwingConstants is true If the input VERTICAL is supplied, a vertical progress bar is created if SwingConstants is true. When the parameter HORIZONTAL is used, a horizontal progress bar is created.

Why Progress Bar Is Important?

This Progress Bar In Java Swing tells the person who is taking the survey how long it might take them to finish it.

This is the single most important thing you can do to help your market research go well.

About the Project: Progress Bar In Java With Source Code

This Progress Bar In Java NetBeans includes a tutorial and a code development guide. This is a simple and basic-level little project for learning purposes. J

Progress Bar is open source, so you can download the zip file and change it to fit your needs.

You can also customize this project to meet your needs and create a fantastic advanced-level project.

Project Details and Technology: Progress Bar In Java

Project Name:Progress Bar In Java
Abstract:This Progress Bar In Java is a simple project that will help IT students learn how to add this progress bar to their projects.
Language/s Used:Java
Java Version (Recommended):11.2
Type:Desktop Application
Developer:Glenn Magada Azuelo
Updates:0
Progress Bar In Java With Source Code – Project Information

The code given below is the full source code on How To Make Progress Bar In Java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package progressbar;

import java.util.Random;

/**
 *
 * @author acer
 */
public class designBar extends javax.swing.JFrame {

    private int PROGRESS_VALUE;
    private Thread PROGRESS_THREAD;

    public designBar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jProgressBar1.setStringPainted(true);

        jButton1.setText("Start Thread");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Click");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Stop");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(121, 121, 121)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addContainerGap(126, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        PROGRESS prog = new PROGRESS();
        PROGRESS_THREAD = new Thread(prog);

        PROGRESS_THREAD.start();

    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here
        PROGRESS_VALUE = new Random().nextInt(100);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        PROGRESS_THREAD.stop();
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(designBar.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(designBar.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(designBar.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(designBar.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new designBar().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration                   

    class PROGRESS implements Runnable {

        @Override
        public void run() {
            while (true) {

                jProgressBar1.setValue(PROGRESS_VALUE);
                try {
                    PROGRESS_THREAD.sleep(100);
                } catch (InterruptedException ex) {

                }
            }
        }
    };

}

This Progress Bar In Java With Source Code also includes a downloadable Project With Source Code for free, just find the downloadable source code below and click to start downloading.

To start executing a Java Project, make sure that you have  NetBeans IDE or any platform of Java installed on your computer.

Progress Bar In Java: Steps on how to run the project

Time needed: 5 minutes

These are the steps on how to run Progress Bar In Java

  • Step 1: Download Source Code

    First, find the downloadable source code below and click to start downloading the source code file.
    Progress Bar In Java Download Button

  • Step 2: Extract File

    Next, after finished to download the file, go to the file location right-click the file, and click extract.
    Progress Bar In Java Extract Files

  • Step 3: Click open project.

    Next, open NetBeans IDE click open project, and choose your download
    Progress Bar In Java Open Project

  • Step 4: Run the project.

    Next, right-click the project folder and click run.
    Progress Bar In Java Run Project

Download the Source Code below!

Summary

The Progress Bar In Java is built fully in Java. It has a full-featured Graphical User Interface (GUI) with all the functionalities

This article is a way to enhance and develop our skills and logic ideas which is important in practicing the Java programming language which is the most well-known and most usable programming language in many companies.

This Simple Project also includes a downloadable source code for free.

Inquiries

If you have any questions or suggestions about Progress Bar In Java With Source Code, please feel free to leave a comment below.

Leave a Comment