How to use progress bar in a java project with source code

Following this tutorial, you can get an idea about how to use progress bar in java project. In this example, I use Netbeans IDE. Here include a video tutorial and source code. You can follow that video with source code.

Do you need help to remotely set up my any project on your machine? or customize any project with your requirement ? please contact  syntech1994@gmail.com

Step 01 Start a new java project.

Step 02 Design a JFrame with Jprogress bar.

Step 03 put these codes inside the main class of project.

Source code

        Home ho = new Home();   // Home is name of the jFrame
        ho.setVisible(true);
        
        try {
             for(int x = 0; x <=100; x++)
        {
        Thread.sleep(120);
        
        Home.lbllord.setText(Integer.toString(x)+"%"); 
        Home.lordbar.setValue(x);
    
        }
        } catch (Exception e) {
        }

Follow the above video to get a clear idea

Don’t Forget Subscribe Us

4 Comments

  1. i can’t get the result as this….
    Why???
    my source code :-
    package Test_Runs;

    import java.awt.EventQueue;

    import javax.swing.JFrame;
    import javax.swing.JProgressBar;
    import javax.swing.SwingConstants;
    import java.awt.Color;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Font;

    public class Ver_PB {

    private JFrame frame;

    /**
    * Launch the application.
    */
    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    Ver_PB window = new Ver_PB();
    window.frame.setVisible(true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    /**
    * Create the application.
    */
    public Ver_PB() {
    initialize();
    }

    /**
    * Initialize the contents of the frame.
    */
    private void initialize() {
    frame = new JFrame();
    frame.getContentPane().setBackground(Color.GRAY);
    frame.setBounds(100, 100, 465, 384);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JProgressBar progressBar = new JProgressBar(SwingConstants.VERTICAL);
    progressBar.setStringPainted(true);
    progressBar.setOpaque(true);
    progressBar.setForeground(Color.YELLOW);

    progressBar.setOrientation(SwingConstants.VERTICAL);
    progressBar.setBounds(36, 10, 29, 262);
    frame.getContentPane().add(progressBar);

    JProgressBar progressBar_1 = new JProgressBar(SwingConstants.HORIZONTAL);
    progressBar_1.setStringPainted(true);
    progressBar_1.setForeground(Color.BLACK);

    progressBar_1.setBounds(75, 282, 247, 30);
    frame.getContentPane().add(progressBar_1);

    JButton btnClickMe = new JButton(“Click Me!!\r\n”);
    btnClickMe.setForeground(Color.LIGHT_GRAY);
    btnClickMe.setBackground(Color.DARK_GRAY);
    btnClickMe.setFont(new Font(“Vivaldi”, Font.BOLD, 40));
    btnClickMe.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    for(int i = 0;i<=100;i++)
    {
    try {
    Thread.sleep(50);
    } catch (InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    progressBar.setValue(i);
    progressBar.setString(i+"%");
    progressBar_1.setValue(i);
    progressBar_1.setString(i+"%");
    }
    }
    });
    btnClickMe.setBounds(75, 10, 247, 262);
    frame.getContentPane().add(btnClickMe);
    }
    }

    my result video:-
    https://drive.google.com/file/d/1PxncNqriJPy33dwyAjV2c7DY0Znhe-HW/view?usp=sharing(40 mb)

  2. Howdy fantastic blog! Does running a blog like this require a large amount of work?
    I’ve very little knowledge of coding however I had been hoping to start
    my own blog soon. Anyhow, should you have any recommendations or tips for
    new blog owners please share. I understand this is off topic but I simply wanted to ask.
    Cheers!

  3. whoah this weblog is great i like studying your articles.
    Keep up the great work! You realize, a lot of persons are hunting around for this info, you could aid
    them greatly.

Leave a Reply

Your email address will not be published.


*