[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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