static86
asked on
set progress bar from a different class
Is it possible to access GUI component like jProgressBar from a different class?
sure, all you need is a reference to the JProgressBar instance
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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)?
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)?
you can make it public but its better design to add a (public) getter to access it as I showed above
ASKER
So how can I show this progress bar on my mainPanel? I can't do drag&drop in netbeans now.
thanks
thanks
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.
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.