1

I have a main class which contains some panel and some buttons, and there is one other class through which I want to set visibility of buttons in main class.

I have added one function to set visibility in main class like:

// This is my main class  
public void setVisibility(boolean flag)  
{   
    mybutton.setVisible(flag);  
}

// this is class which calls the method,
my_constructor.setVisibility(false);

but this is not working, can anybody help?

1
  • 1
    Can you provide some more code in your example? This should work fine, even without a call to repaint() (invalidate() would actually be better!). Maybe check your threads if the EDT isn't being held up somewhere? Jan 10, 2011 at 12:04

2 Answers 2

0

Did you try to repaint the panel after setting the visibility?

// This is my main class  
public void setVisibility(boolean flag)  
{   
    mybutton.setVisible(flag);  
    myPanel.repaint();
}
0
0

Is your call to the setVisibility(boolean) method on the EventDispatcherThread? (can't tell from the little code you posted).

Runnable runnable = new Runnable() {
   public void run() {
       setVisibility(flag);
   }
 };

EventQueue.invokeLater(runnable);

Another minor point is you are encapsulating a call to the setVisible() method with a method named setVisibility(). If I had to maintain that code after you I would be cursing your name:-) IMHO, just make the method name the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.