• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

set progress bar from a different class

Is it possible to access GUI component like jProgressBar from a different class?
0
static86
Asked:
static86
  • 5
  • 2
1 Solution
 
objectsCommented:
sure, all you need is a reference to the JProgressBar instance
0
 
objectsCommented:
For example you could add a getter to your class to allow other classes to access it

public class MyPanel extends JPanel {
   private JProgressBar bar = new JProgressBar();

   public JProgressBar getProgressBar() {
       return bar;
   }

   ....


Then from another class you could access it using the getter


JProgressBar bar = mypanel.getProgressBar();
// do what you need to the progress bar

0
 
objectsCommented:
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
static86Author Commented:
thanks objects,
I have created jProgressBar within Netbeans and it is already in mainPanel [JPanel] so is it possible to make progressBar public and refer to that (or something similar)?
0
 
objectsCommented:
you can make it public but its better design to add a (public) getter to access it as I showed above
0
 
static86Author Commented:
So how can I show this progress bar on my mainPanel? I can't do drag&drop in netbeans now.
thanks
0
 
objectsCommented:
Thats the problem with using netbeans and its gui builder. it takes a lot of the control away from you.
if you're using netbeans then create your gui with netbeans and once you're done add methods to provide any interaction between classes that you need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now