Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:40:13+00:00 2026-06-11T00:40:13+00:00

I have a progressbar in a.java class(in form).I need to reach it from b.java

  • 0

I have a progressbar in a.java class(in form).I need to reach it from b.java class .
My progressbar name is jprog.(I put it in form from palet)
How can I set public my progressbar? I cant find it in properties page.
my progressbarr in first class. But I want to change its value in second class.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:40:14+00:00Added an answer on June 11, 2026 at 12:40 am

    Consider adding a PropertyChangeListener to your first class and using a SwingWorker in your second class. SwingWorker has a method called setProgress() that you can invoke to set the value of your progress bar. You can then override the propertyChange() method in your first class and do something like this:

    public void propertyChange(PropertyChangeEvent evt) {
        if ("progress" == evt.getPropertyName()) {
          int progress = (Integer) evt.getNewValue();
          progressBar.setValue(progress);
        }
    }
    

    An example using a couple of classes, ClassA and ClassB can be as follows:

    public ClassA extends JForm implements PropertyChangeListener{
        private JProgressBar progressBar;
    
        public ClassA(){
            /**
            * Your setup for the form
            */
        }
    
         /**
         * Invoked when task's progress property changes.
         */
        public void propertyChange(PropertyChangeEvent evt) {
            if ("progress" == evt.getPropertyName()) {
                int progress = (Integer) evt.getNewValue();
                progressBar.setValue(progress);
            }
        }
    
        public void someMethod(){
            ClassB classB = new ClassB();
            classB.addPropertyChangeListener(this);
            classB.execute();
        }
    }
    
    class ClassB extends SwingWorker<Void, Void> {
            /*
             * Main task. Executed in background thread.
             */
            @Override
            public Void doInBackground() {
                Random random = new Random();
                int progress = 0;
                //Initialize progress property.
                setProgress(0);
                //Sleep for at least one second to simulate "startup".
                try {
                    Thread.sleep(1000 + random.nextInt(2000));
                } catch (InterruptedException ignore) {}
                while (progress < 100) {
                    //Sleep for up to one second.
                    try {
                        Thread.sleep(random.nextInt(1000));
                    } catch (InterruptedException ignore) {}
                    //Make random progress.
                    progress += random.nextInt(10);
                    setProgress(Math.min(progress, 100));
                }
                return null;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone have shining progressbar component for java swing application?
I have the following code in Main.java : public class Main extends Activity implements
I have a progressBar using the ProgressBar class. Just doing this: progressBar = new
I have created a form on which two components are present, button and progressbar
For a few days a have some problem. I need to show simple ProgressBar
I have two class fils upload.java and transferProgress.java . upload.java makes applet GUI and
I have just started out with .php/Java can someone show me how to get
I have an image called 'progressbar.png'. Is there a way that I could crop
I have been playing around with the Silverlight progressbar a while and no matter
I am trying to use performance progressbar in a WP7 project but I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.