设置一个类的 jButton 在另一个类中的可见性
我有一个主类,其中包含一些面板和一些按钮,还有另一个类,我想通过它设置主类中按钮的可见性。
我添加了一个函数来设置主类中的可见性 喜欢:
// This is my main class
public void setVisibility(boolean flag)
{
mybutton.setVisible(flag);
}
// this is class which calls the method,
my_constructor.setVisibility(false);
但这不起作用,有人可以帮忙吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试在设置可见性后重新绘制面板?
Did you try to repaint the panel after setting the visibility?
您是否调用了 EventDispatcherThread 上的 setVisibility(boolean) 方法? (无法从您发布的小代码中看出)。
另一个小问题是您正在使用名为 setVisibility() 的方法封装对 setVisible() 方法的调用。如果我必须在你之后维护该代码,我会咒骂你的名字:-) 恕我直言,只需使方法名称相同即可。
Is your call to the setVisibility(boolean) method on the EventDispatcherThread? (can't tell from the little code you posted).
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.