We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

set progress bar from a different class

static86
static86 asked
on
Medium Priority
396 Views
Last Modified: 2012-05-11
Is it possible to access GUI component like jProgressBar from a different class?
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
sure, all you need is a reference to the JProgressBar instance
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

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)?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
you can make it public but its better design to add a (public) getter to access it as I showed above

Author

Commented:
So how can I show this progress bar on my mainPanel? I can't do drag&drop in netbeans now.
thanks
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.